# Kling Image 4 API Documentation > LLM-optimized documentation for Kling Image 4. Copy into your AI assistant for integration help. ## Overview **Model ID:** `kling-image-4` **Type:** Image Generation **Credit Cost:** 1.75 credits per image Kling IMAGE 4.0: native 2K, 4K and 8K images with sharp text in seven languages, consistent series of up to 10 images, and full product pages or website designs from one prompt. Up to 10 reference images. ## Endpoint ``` POST https://pixeldojo.ai/api/v1/models/kling-image-4/run ``` ## Authentication All requests require an API key in the Authorization header: ``` Authorization: Bearer YOUR_API_KEY ``` Get your API key: https://pixeldojo.ai/api-platform/api-keys ## Input Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | `prompt` | string | Yes | - | What to make. Name reference images as <<>>, <<>> and so on. Up to 50,000 ASCII characters (166,000 for product pages and websites); non-ASCII characters count more. | | `mode` | enum | No | image | image: one or more images. series: 2-10 planned images that keep the same subjects and style. ecommerce: a full product detail page from your product photo (image_urls required). webpage: a website design. Pages come back as one tall image. (Options: image, series, ecommerce, webpage) | | `image_urls` | array | No | - | Optional reference image URLs (1 to 10, at most 3 for ecommerce/webpage). Each at least 300 px, aspect between 1:2.5 and 2.5:1. | | `resolution` | enum | No | 2K | 2K, 4K or 8K for image and series; 1K or 2K for ecommerce and webpage. (Options: 1K, 2K, 4K, 8K) | | `aspect_ratio` | enum | No | auto | Output shape for image and series. auto matches the first reference image, or lets the model pick from the prompt. Ignored for pages. (Options: auto, 1:1, 3:2, 2:3, 4:3...) | | `num_outputs` | integer | No | 1 | Image mode only: number of separate images (1-4). (min: 1, max: 4) | | `series_length` | integer | No | 4 | Series mode only: number of images in the set (2-10). Charged per image. (min: 2, max: 10) | | `page_length` | enum | No | medium | Ecommerce mode only: short (2-5 sections), medium (6-10) or long (11-18). (Options: short, medium, long) | ## Supported Aspect Ratios - `auto` - `1:1` - `3:2` - `2:3` - `4:3` - `3:4` - `16:9` - `9:16` - `21:9` ## Capabilities - Text to Image - Image to Image ## Quick Start ### 1. Submit a Job ```bash curl -X POST "https://pixeldojo.ai/api/v1/models/kling-image-4/run" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "prompt": "a neon ramen shop on a rainy Tokyo side street at night, sign reading \"MIDNIGHT NOODLES\", cinematic photo", "resolution": "4K", "aspect_ratio": "16:9" }' ``` **Response:** ```json { "jobId": "job_abc123...", "status": "pending", "statusUrl": "https://pixeldojo.ai/api/v1/jobs/job_abc123", "creditCost": 1.75, "creditsRemaining": 95 } ``` ### 2. Poll for Results ```bash curl "https://pixeldojo.ai/api/v1/jobs/job_abc123" \ -H "Authorization: Bearer YOUR_API_KEY" ``` **Completed Response:** ```json { "jobId": "job_abc123...", "status": "completed", "output": { "images": ["https://temp.pixeldojo.ai/..."] }, "creditCost": 1.75 } ``` ## Python Example ```python import requests import time API_KEY = "YOUR_API_KEY" # Submit job response = requests.post( "https://pixeldojo.ai/api/v1/models/kling-image-4/run", headers={ "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" }, json={ "prompt": "a neon ramen shop on a rainy Tokyo side street at night, sign reading \"MIDNIGHT NOODLES\", cinematic photo", "resolution": "4K", "aspect_ratio": "16:9" } ) job = response.json() job_id = job["jobId"] # Poll for completion while True: status_response = requests.get( f"https://pixeldojo.ai/api/v1/jobs/{'{job_id}'}", headers={"Authorization": f"Bearer {API_KEY}"} ) status = status_response.json() if status["status"] == "completed": print("Output:", status["output"]) break elif status["status"] == "failed": print("Error:", status.get("error")) break time.sleep(2) ``` ## JavaScript Example ```javascript const API_KEY = 'YOUR_API_KEY'; // Submit job const submitResponse = await fetch('https://pixeldojo.ai/api/v1/models/kling-image-4/run', { method: 'POST', headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ "prompt": "a neon ramen shop on a rainy Tokyo side street at night, sign reading \"MIDNIGHT NOODLES\", cinematic photo", "resolution": "4K", "aspect_ratio": "16:9" }) }); const job = await submitResponse.json(); // Poll for completion const pollForResult = async (jobId) => { while (true) { const statusResponse = await fetch(`https://pixeldojo.ai/api/v1/jobs/${jobId}`, { headers: { 'Authorization': `Bearer ${API_KEY}` } }); const status = await statusResponse.json(); if (status.status === 'completed') return status.output; if (status.status === 'failed') throw new Error(status.error); await new Promise(r => setTimeout(r, 2000)); } }; const output = await pollForResult(job.jobId); console.log('Output:', output); ``` ## Use Saved Characters (@Name) Write `@Name` in the prompt to use a character, product, outfit, location, prop or style saved in the account's Character Studio, for example `"@Mara on a beach at sunset"`. Its photos are added to `image_urls` automatically, after any images you send yourself, so your own image numbering is unchanged. List saved names with `GET /api/v1/characters` and save new ones with `POST /api/v1/characters`. An `@word` that names nothing saved stays plain text. ## Error Codes | Code | Status | Description | |------|--------|-------------| | `unauthorized` | 401 | Invalid or missing API key | | `insufficient_credits` | 402 | Not enough credits | | `invalid_request` | 400 | Invalid parameters | | `model_not_found` | 404 | Model ID not found | | `internal_error` | 500 | Server error | ## Links - **Full Documentation:** https://pixeldojo.ai/api-platform/kling-image-4 - **API Keys:** https://pixeldojo.ai/api-platform/api-keys - **Buy Credits:** https://pixeldojo.ai/api-platform/buy-credits - **All Models:** https://pixeldojo.ai/api/v1/models - **OpenAPI Spec:** https://pixeldojo.ai/api/openapi