# Kling 4.0 API Documentation > LLM-optimized documentation for Kling 4.0. Copy into your AI assistant for integration help. ## Overview **Model ID:** `kling-4-0` **Type:** Video Generation **Credit Cost:** 25 credits per video Kling Video 4.0. Up to 30 seconds at 1080p with native audio and dialogue: text, start/end frames, reference images and videos, or edit an existing clip. ## Endpoint ``` POST https://pixeldojo.ai/api/v1/models/kling-4-0/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 happens in the clip. Timed beats, camera moves and quoted dialogue all work. Refer to inputs as <<>> (frames first, then reference images) and <<>> (source video first, then reference videos). | | `image` | url | No | - | Optional first frame. The image sets the aspect ratio. | | `last_frame_image` | url | No | - | Optional last frame. Requires image. | | `reference_images` | array | No | - | Up to 10 images (frames included) for cast, products, locations or a storyboard. | | `video` | url | No | - | A clip to edit with the prompt (swap a product, add or remove a subject, restyle). Set duration to the clip length; billed at the video-input rate. | | `reference_videos` | array | No | - | Up to 5 clips (30 s total) whose motion, camera path or structure to carry over. Billed at the video-input rate. | | `resolution` | enum | No | 1080p | Output resolution (Options: 720p, 1080p) | | `aspect_ratio` | enum | No | 16:9 | Text-to-video only; inputs set their own shape. (Options: 16:9, 9:16, 1:1, 21:9) | | `duration` | integer | No | 5 | Clip length in seconds (3-30). With video, the source clip length. (min: 3, max: 30) | ## Supported Aspect Ratios - `16:9` - `9:16` - `1:1` - `21:9` ## Capabilities - Text to Video - Image to Video - Audio Generation ## Quick Start ### 1. Submit a Job ```bash curl -X POST "https://pixeldojo.ai/api/v1/models/kling-4-0/run" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "prompt": "0-4s: slow push in on a barista in a rainy cafe. 4-10s: she looks up and says \"Last order of the night.\" Audio: rain on glass, espresso hiss.", "duration": 10, "resolution": "1080p" }' ``` **Response:** ```json { "jobId": "job_abc123...", "status": "pending", "statusUrl": "https://pixeldojo.ai/api/v1/jobs/job_abc123", "creditCost": 25, "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": { "video": "https://temp.pixeldojo.ai/..." }, "creditCost": 25 } ``` ## Python Example ```python import requests import time API_KEY = "YOUR_API_KEY" # Submit job response = requests.post( "https://pixeldojo.ai/api/v1/models/kling-4-0/run", headers={ "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" }, json={ "prompt": "0-4s: slow push in on a barista in a rainy cafe. 4-10s: she looks up and says \"Last order of the night.\" Audio: rain on glass, espresso hiss.", "duration": 10, "resolution": "1080p" } ) 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-4-0/run', { method: 'POST', headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ "prompt": "0-4s: slow push in on a barista in a rainy cafe. 4-10s: she looks up and says \"Last order of the night.\" Audio: rain on glass, espresso hiss.", "duration": 10, "resolution": "1080p" }) }); 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 `reference_images` 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-4-0 - **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