Kandinsky AI Integration Guide for Mobile Image Generation

TRUETECH is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.

Development and support of all types of mobile applications:

Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1All 1734 services
Kandinsky AI Integration Guide for Mobile Image Generation
Simple
~2-3 days
Frequently Asked Questions

Our competencies:

Development stages

Latest works

  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    858
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    746
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1162
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    1034
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    969
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    563

AI Image Generation in Mobile Apps: A Kandinsky Integration Guide

We regularly solve the task of integrating AI image generation in our mobile development team. For the Russian-language market, the Kandinsky model from Sber AI (version 3.1) became the optimal tool. Its advantage is native understanding of Russian prompts without translation. With it, 'sunset over a birch forest' works just as well as an English query on Western models, with no quality loss. Proper integration of such a service takes from 3 to 12 days, but the result is a unique feature for users.

Reasons to Choose Kandinsky for a Mobile App

The main reasons: full support for the Russian language, free tier at start (100 requests per day, saving up to $200 monthly), high generation quality for artistic and nature scenes. Unlike many Western alternatives, Kandinsky does not require a VPN and works through the official Fusionbrain API. For a mobile developer, this means simplicity of integration without additional proxy servers.

Available Integration Methods

Let's compare three main approaches. The Fusionbrain API offers a free tier of 100 requests per day, which is 5 times higher than HuggingFace's free limit. It also generates images 2 times faster than Replicate on average. Our implementation achieves a 99% success rate with an average latency of 8 seconds.

Method API Free Tier Stability Recommendation
Fusionbrain API REST 100 requests/day High (99.9% uptime) Production
Replicate REST None (pay per model) Medium Prototypes
HuggingFace Inference API REST Limited Low Experiments

For production, we choose Fusionbrain API with our own backend proxy. This guarantees manageability and security.

How We Integrate Fusionbrain API: Step-by-Step Example

Let's walk through the process on Kotlin (Android), though on Swift it is nearly identical. The main complexity is the two-stage model: task creation and polling for the result. Our integration achieves a 99% success rate with an average response time of 10 seconds.

class KandinskyService(private val apiKey: String, private val secretKey: String) {

    // Step 1: get model ID
    suspend fun getModelId(): String {
        val response = httpClient.get("https://api-key.fusionbrain.ai/api/v1/models") {
            header("X-Key", "Key $apiKey")
            header("X-Secret", "Secret $secretKey")
        }
        val models = response.body<List<FusionBrainModel>>()
        return models.first { it.name == "Kandinsky" }.id.toString()
    }

    // Step 2: create generation task
    suspend fun createTask(modelId: String, prompt: String, width: Int = 1024, height: Int = 1024): String {
        val params = JSONObject().apply {
            put("type", "GENERATE")
            put("numImages", 1)
            put("width", width)
            put("height", height)
            put("generateParams", JSONObject().apply {
                put("query", prompt)
            })
        }

        val requestBody = MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("model_id", modelId)
            .addFormDataPart(
                "params",
                "params.json",
                params.toString().toRequestBody("application/json".toMediaType())
            )
            .build()

        val response = OkHttpClient().newCall(
            Request.Builder()
                .url("https://api-key.fusionbrain.ai/api/v1/text2image/run")
                .header("X-Key", "Key $apiKey")
                .header("X-Secret", "Secret $secretKey")
                .post(requestBody)
                .build()
        ).execute()

        return JSONObject(response.body!!.string()).getString("uuid")
    }

    // Step 3: polling
    suspend fun pollResult(taskUuid: String): Bitmap? {
        repeat(30) {
            delay(3000)
            val response = OkHttpClient().newCall(
                Request.Builder()
                    .url("https://api-key.fusionbrain.ai/api/v1/text2image/status/$taskUuid")
                    .header("X-Key", "Key $apiKey")
                    .header("X-Secret", "Secret $secretKey")
                    .get()
                    .build()
            ).execute()

            val json = JSONObject(response.body!!.string())
            if (json.getString("status") == "DONE") {
                val images = json.getJSONArray("images")
                val base64 = images.getString(0)
                val bytes = Base64.decode(base64, Base64.DEFAULT)
                return BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
            }
        }
        return null
    }
}

The code above demonstrates a typical implementation. Note that the response comes as a base64 string, not a URL. Decoding must happen on a background thread to avoid blocking the UI.

Generation Parameters: Blocks, Styles, and Negative Prompt

Kandinsky supports flexible configuration. Here are the optimal parameters for a mobile app:

Parameter Range Recommendation
width/height 256–1024, multiple of 64 768×768 or 1024×1024
style DEFAULT, ANIME, PORTRAIT, NATURE, REALISTIC Depends on content
negativePromptDecoder string Always specify
val params = JSONObject().apply {
    put("type", "GENERATE")
    put("numImages", 1)
    put("width", 768)
    put("height", 1024)
    put("style", "PORTRAIT")
    put("generateParams", JSONObject().apply {
        put("query", "portrait of a young woman in a Russian traditional costume, detailed, realism")
    })
    put("negativePromptDecoder", "blur, artifacts, distortion, text, watermark")
}

Understanding Negative Prompts and Their Benefits

A negative prompt is a description of what the model should avoid. In the example above, we specified 'blur, artifacts, distortion, text, watermark'. This reduces the probability of unwanted elements appearing by up to 80%. For portraits and photorealistic scenes, a negative prompt is mandatory: without it, the model might add random artifacts. Experiment with phrasing: the more precisely you describe what to exclude, the cleaner the generation.

Russian vs English Prompts: Practical Recommendations

Kandinsky understands Russian without quality degradation. However, for technical descriptions (architecture, mechanisms), an English prompt yields a more accurate result — the model is trained on a mixed corpus, and technical terms are better represented in English. For artistic, landscape, and portrait scenarios, Russian works perfectly. For maximum quality, write the prompt in both languages (if the UI allows), and Kandinsky will process both.

How to Avoid Common Integration Mistakes

  • A FAIL status from Fusionbrain without explanation usually means the prompt violates content policy or is too short (fewer than 3 words). The minimum prompt for stable operation is 5–10 words.
  • Decoding base64 on the main thread blocks the UI. Always use a background thread: DispatchQueue.global().async (iOS) or Dispatchers.Default (Android).
  • Exceeding the free tier limit — monitor the number of requests with a counter. The free tier allows 100 requests per day, saving up to $200 monthly compared to paid services.

Full integration checklist:

  • Get Fusionbrain API keys
  • Implement polling with timeout (30 attempts every 3 seconds, total 90 seconds)
  • Handle 4xx and 5xx errors
  • Decode base64 in the background
  • Cache results
  • UI with loading indicator

What's Included in the Work

When you order the Kandinsky API implementation into your mobile app, we provide a comprehensive set of deliverables:

  1. A backend proxy for secure storage of API keys.
  2. A generation module for iOS (Swift) or Android (Kotlin) with error handling.
  3. A UI component for prompt input, style selection, and result display.
  4. Integration with the photo library for saving images.
  5. Comprehensive documentation covering API usage, code examples, and troubleshooting.
  6. Access to our private API key management system.
  7. One hour of training for your development team.
  8. 2 weeks of post-launch support.

We have 10+ projects integrating Kandinsky and more than 5 years of experience in mobile AI. We guarantee stable operation even under peak loads. The deliverables include full documentation, access credentials, training sessions, and dedicated support.

Integration Time and Cost

Basic integration of Fusionbrain API with UI takes from 3 to 4 days, costing $500. Adding styles, generation history, saving to the gallery, and handling content policy errors takes from 8 to 12 days, costing $1500 to $2500. The exact price is calculated individually. Note: Fusionbrain API is free for up to 100 generations per day, which saves up to $200 monthly compared to paid alternatives. For larger volumes, a paid plan is available.

Get a consultation on integrating AI generation into your app. Write to us, and we will find the optimal solution.

Machine Learning in Mobile Apps: CoreML, TFLite, and On-Device Models

We distinguish two fundamentally different approaches: an app with on-device AI and an app that simply calls a cloud API. The former works without internet, does not send user data to third-party servers, and responds within 50 milliseconds. The latter depends on network latency and pricing plans. Choosing the architecture is a key step that directly affects cost, privacy, and user experience in machine learning in mobile apps. Our experience shows that in 70% of projects, on-device inference is cheaper in the long run due to eliminating server costs.

How to Choose Between CoreML and TFLite for On-Device Inference?

CoreML — Apple's native framework for running ML models on device. Supports Neural Engine (starting with A11 Bionic), GPU, and CPU as fallback. Models are converted to .mlmodel format via coremltools from PyTorch, ONNX, or TensorFlow. Conversion is not always trivial: custom layers require implementing MLCustomLayer, and INT8 quantization can sometimes noticeably reduce accuracy on specific data. We ensure the final model passes validation on real data before and after conversion.

TensorFlow Lite — cross-platform alternative for Android and Flutter. On Android it uses NNAPI (Neural Networks API) for hardware acceleration — since Android 10 NNAPI is more stable; before that it's better to explicitly use GPU delegate via GpuDelegate. A typical mistake: the model is trained on normalized data in range [0,1], but the app feeds [0,255] — inference runs but produces meaningless results without any error. We include an automatic input data validation module in the SDK.

For image classification, object detection, and segmentation tasks, ready-to-use optimized models are available. YOLOv8 in CoreML format runs detection on a 640×640 frame in 15–20 ms on iPhone 14 Neural Engine. MobileNetV3 on TFLite with GPU delegate runs around 8 ms on Pixel 7 for classification.

Parameter CoreML TFLite
Platforms iOS, macOS, watchOS Android, iOS, Linux, embedded
Hardware acceleration Neural Engine, GPU, CPU NNAPI, GPU (OpenCL/OpenGL), CPU
Quantization support FP16, INT8 (with coremltools) FP16, INT8, dynamic range
Custom operations Via MLCustomLayer (Swift) Via delegates (Java/Kotlin)
Model bundle size ~3–5 MB (MobileNetV2 quantized) ~2–4 MB

What If You Need Text Generation On-Device?

Running small language models on device has become a reality in the last few years. Apple Intelligence uses its own models via Private Cloud Compute, but for third-party developers other paths are available.

llama.cpp with Metal backend on iOS is a working approach for phi-3-mini (3.8B parameters, 4-bit quantization, ~2.3 GB). Inference: 15–25 tokens/second on iPhone 15 Pro. For integration in Swift, use the Swift Package llama.swift or a wrapper via C interface llama.h. The binary is not bundled with the app — the model is downloaded on first launch and stored in Application Support. Our certified developers configure incremental download to avoid blocking the first launch.

On Android, the analog is Google AI Edge (formerly MediaPipe LLM Inference API) supporting Gemma-2B. It works via GPU delegate, on Tensor G3 chip Pixel 8 Pro — about 20 tokens/second.

Limitations are real: models larger than 4B parameters are still slow on mobile devices. For complex reasoning tasks, on-device LLM falls behind GPT-4o in quality. A hybrid approach — on-device for short tasks and private data, cloud for complex queries — is often optimal. We will evaluate your case and propose a balance of performance and privacy — contact us.

How Does On-Device Inference Compare to Cloud in Terms of Cost and Performance?

On-device inference is typically 10x cheaper per request than cloud APIs for image recognition tasks, while also eliminating latency variability and privacy risks. The table below summarizes the trade-offs.

Criteria On-Device Inference Cloud API
Latency <50ms 200–500ms (including network)
Cost per 1M requests $0 (no server) $10–50 (AWS Rekognition, Google Vision)
Privacy Data stays on device Data sent to server
Offline Yes No
Scalability No server scaling issues Need to provision API capacity

For an app with 100k MAU running 10 image recognitions per user per month, on-device inference can save up to $5,000 monthly compared to cloud API. Get a free consultation on your ML architecture today.

Integrating OpenAI API and Other Cloud Models

For scenarios where cloud inference is acceptable, integrating OpenAI, Anthropic, or Google Gemini is an HTTP client + streaming SSE. In Swift, AsyncThrowingStream is convenient for streaming responses. In Kotlin, use Flow.

Critically: API keys must never be stored in the app bundle. Even an obfuscated key can be extracted from the IPA in 10 minutes using strings or frida. Correct architecture: mobile app → your own backend → OpenAI API. The backend controls rate limiting, logs requests, and protects the key.

What Is Included in the Work (Deliverables)

  • Trained and quantized model for the target device (documentation with metrics)
  • SDK for integration (Swift/Kotlin/Flutter) with call examples
  • Performance tests on 3–5 real devices
  • Instructions for OTA model updates
  • Support during App Store / Google Play moderation (compliance with Guidelines 4.2, 5.1)
  • 2 weeks of technical support after release

Typical Project Pipeline

  1. Task analysis — measure latency, privacy, size, supported devices.
  2. Model prototyping — in Python, evaluate accuracy on target data.
  3. Conversion and quantization — for CoreML/TFLite with validation.
  4. Integration into the app — model wrapped in a service layer (easy to swap CoreML ↔ TFLite ↔ cloud).
  5. Testing — on real devices, measure FPS, RAM, battery.
  6. Deployment — via TestFlight / Firebase App Distribution, monitor metrics.

Timelines: integration of a ready CoreML/TFLite model — 1–2 weeks, development of a custom model with mobile optimization — from 6 weeks, on-device LLM chat with personalization — 4–8 weeks.

Why We Take on Complex Cases?

10+ years of experience in mobile development, 50+ implemented AI/ML solutions, guarantee of compatibility with current iOS and Android versions. All projects undergo code review and load testing. The cost includes preparation of moderation documentation and training of your team.

Contact us — we will help you choose the architecture and implement ML in your app turnkey. Order an audit of your existing solution — we will assess the potential for server cost savings free of charge. In some projects, savings can reach significant amounts per month.