Animates a start image into a 3–30 second video, with optional keyframes and end frame, at 720p, 1080p or 4k.
Keys start with rsw_ and are shown once when created. Keep the key on your server and expose it to your code as RAWSWITCH_API_KEY.
export RAWSWITCH_API_KEY="rsw_live_…"Every model answers the same endpoint. The body is an envelope: model picks the model, input carries the model's own fields, and webhook, route and tags are optional.
curl -X POST https://rawswitch.ai/v1/requests \
-H "Authorization: Bearer $RAWSWITCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling/kling-4.0-image-to-video",
"input": {
"prompt": "The mug turns slowly on the table as steam rises",
"image_url": "https://files.rawswitch.example/samples/mug.jpg",
"duration": 5,
"resolution": "1080p"
}
}'The request is accepted and queued. You get an id and the URLs to follow it.
{
"id": "req_01JDF3K8Q2",
"status": "queued",
"urls": {
"self": "https://rawswitch.ai/v1/requests/req_01JDF3K8Q2",
"events": "https://rawswitch.ai/v1/requests/req_01JDF3K8Q2/events",
"cancel": "https://rawswitch.ai/v1/requests/req_01JDF3K8Q2/cancel"
}
}Send the key in the Authorization header as a bearer token. Calls without a valid key fail with error.type = "authentication_error".
Authorization: Bearer $RAWSWITCH_API_KEYA request moves through queued → running → succeeded, failed or canceled. For short jobs you can ask the submit call to wait: it returns whatever state the request reached within the limit.
curl -X POST "https://rawswitch.ai/v1/requests?wait=60" \
-H "Authorization: Bearer $RAWSWITCH_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6b1f0c1e-2f0a-4c57-9a55-1d2f6f0b7c11" \
-d @body.jsonIdempotency-Key with every submit and reuse it when you retry. Without it, a retry can run and bill twice.One call returns the status and, once finished, the output.
curl https://rawswitch.ai/v1/requests/req_01JDF3K8Q2 \
-H "Authorization: Bearer $RAWSWITCH_API_KEY"Follow a request live over server-sent events instead of polling.
curl -N https://rawswitch.ai/v1/requests/req_01JDF3K8Q2/events \
-H "Authorization: Bearer $RAWSWITCH_API_KEY"
event: status
data: {"status":"running"}
event: status
data: {"status":"succeeded"}served_by names the path that produced the output and attempts lists everything that was tried. Nothing about routing is hidden.
{
"id": "req_01JDF3K8Q2",
"model": "kling/kling-4.0-image-to-video",
"status": "succeeded",
"output": {
"videos": [
{
"url": "https://files.rawswitch.example/req_01JDF3/kling-4.0-image-to-video-0.mp4",
"content_type": "video/mp4",
"bytes": 4821933,
"width": 1280,
"height": 720,
"duration_seconds": 5
}
]
},
"served_by": "partner/gateway",
"attempts": [
{
"route": "partner/gateway",
"status": "succeeded"
}
],
"usage": {
"unit": "video",
"quantity": 1
},
"timings": {
"queued_ms": 38,
"running_ms": 4120
}
}curl -X POST https://rawswitch.ai/v1/requests/req_01JDF3K8Q2/cancel \
-H "Authorization: Bearer $RAWSWITCH_API_KEY"Inputs take URLs. Public URLs work as they are. For local files, ask for an upload URL, send the bytes there and pass the returned file_url.
# 1) ask for an upload URL
curl -X POST https://rawswitch.ai/v1/files \
-H "Authorization: Bearer $RAWSWITCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"filename": "jacket-front.jpg", "content_type": "image/jpeg"}'
# 2) send the bytes to upload_url, then use file_url in your input
curl -X PUT "$UPLOAD_URL" -H "Content-Type: image/jpeg" --data-binary @jacket-front.jpgAdd a webhook to the request and Rawswitch posts the finished request to your URL. Deliveries are signed with the Standard Webhooks scheme and retried when your endpoint fails.
{
"model": "kling/kling-4.0-image-to-video",
"input": {},
"webhook": {
"url": "https://your-app.example/hooks/rawswitch"
}
}| Field | Type | Required | Description |
|---|---|---|---|
| prompt | string | — | Optional. How the frames should move: the motion and the camera. |
| image_url | string (URL) | yes | The first frame of the video. At least 300 px per side, aspect ratio between 0.4 and 2.5, up to 30 MB. |
| middle_image_urls | string[] (URL) | — | Up to 8 frames to pass through between the start and the end, in order. They count toward the image limit. Up to 8 URLs. |
| end_image_url | string (URL) | — | Optional last frame. The video moves from the start image to this one. |
| duration | integer | — | Length of the video in seconds (3–30). Billed per second. Default 5. |
| resolution | enum | — | Output resolution. Higher resolutions cost more per second. One of 720p, 1080p, 4k. Default "1080p". |
| hdr | boolean | — | 10-bit HDR instead of SDR. Only at 1080p and 4k, billed per second on top of the base price. Default false. |
Finished files are in output.videos: one item per video with url, content_type and bytes, plus width, height and duration_seconds when they can be read from the file.
| Field | Type | Description |
|---|---|---|
| videos | array | Generated videos. Each item has url, content_type and bytes, plus width, height and duration_seconds when they can be read from the file. |
{
"videos": [
{
"url": "https://files.rawswitch.example/req_01JDF3/kling-4.0-image-to-video-0.mp4",
"content_type": "video/mp4",
"bytes": 4821933,
"width": 1280,
"height": 720,
"duration_seconds": 5
}
]
}Paths behind this model:
partner/gateway — Partner gateway (Primary)Paste this into a coding agent. It carries the endpoint, the schema and the rules for calling this model safely.
You are adding the Rawswitch model `kling/kling-4.0-image-to-video` (Kling 4.0 Image to Video — image to video) to this codebase.
## What it does
Animates a start image into a 3–30 second video, with optional keyframes and end frame, at 720p, 1080p or 4k.
Price: $0.24675 per second (1080p).
## API
- Base URL: https://rawswitch.ai
- Auth: header `Authorization: Bearer <key>`. Read the key from the `RAWSWITCH_API_KEY` environment variable. Never hard-code it and never send it to the browser.
- Submit: `POST /v1/requests` with JSON `{ model, input, webhook?, route?, tags? }`. The response is `{ id, status: "queued", urls }`.
- Result: `GET /v1/requests/{id}` until `status` is `succeeded`, `failed` or `canceled`. One call returns status and output together.
- Short jobs: `POST /v1/requests?wait=60` waits up to 60 seconds and returns whatever state the request reached.
- Live status: `GET /v1/requests/{id}/events` is a server-sent event stream.
- Cancel: `POST /v1/requests/{id}/cancel`.
- Files: `POST /v1/files` returns `{ upload_url, file_url }`. PUT the bytes to `upload_url`, then pass `file_url` in the input.
## Request
```json
{
"model": "kling/kling-4.0-image-to-video",
"input": {
"prompt": "The mug turns slowly on the table as steam rises",
"image_url": "https://files.rawswitch.example/samples/mug.jpg",
"duration": 5,
"resolution": "1080p"
}
}
```
## Input fields
- `prompt` (string): Optional. How the frames should move: the motion and the camera.
- `image_url` (URL, required): The first frame of the video. At least 300 px per side, aspect ratio between 0.4 and 2.5, up to 30 MB.
- `middle_image_urls` (array of URLs, at most 8 items): Up to 8 frames to pass through between the start and the end, in order. They count toward the image limit.
- `end_image_url` (URL): Optional last frame. The video moves from the start image to this one.
- `duration` (integer, range 3–30, default 5): Length of the video in seconds (3–30). Billed per second.
- `resolution` (string, one of "720p", "1080p", "4k", default "1080p"): Output resolution. Higher resolutions cost more per second.
- `hdr` (boolean, default false): 10-bit HDR instead of SDR. Only at 1080p and 4k, billed per second on top of the base price.
## Output
- `videos` (array): Generated videos. Each item has url, content_type and bytes, plus width, height and duration_seconds when they can be read from the file.
```json
{
"videos": [
{
"url": "https://files.rawswitch.example/req_01JDF3/kling-4.0-image-to-video-0.mp4",
"content_type": "video/mp4",
"bytes": 4821933,
"width": 1280,
"height": 720,
"duration_seconds": 5
}
]
}
```
## Rules to follow
- Send an `Idempotency-Key` header (a UUID per logical job) on every submit, and reuse the same key when you retry. A retry without it can run and bill twice.
- Do not poll faster than once per second. Prefer `?wait=`, the event stream or a webhook over tight polling.
- On `failed`, branch on `error.type`; show `error.message` to the user. Do not switch to another model yourself: Rawswitch already retries the same model on another path, and a different model is a product decision.
- Log `id`, `served_by` and `attempts` with your own request log. They say which path served the call.
- Output file URLs are for download. Copy the files into your own storage if you need to keep them.
- If you receive webhooks, verify the Standard Webhooks signature before trusting the body.
## Paths behind this model
- `partner/gateway` — Partner gateway (primary)
Write a small typed function that submits a request, waits for the result and returns the output. Add one test that mocks the HTTP calls.Base URL in these examples is https://rawswitch.ai, a placeholder until the domain is decided.