Rawswitch
  • 路由
  • 文档
ENKOJAZH
联系我们获取 API 密钥

浏览

  • 全部模型
  • 图像
  • 视频

路径

  • 供应商直连 API
  • 合作网关
  • 自有 NPU
精选
在自有 NPU 上识别商品属性

产品

  • 路由 API
  • 模型
  • 在线体验
  • 共享路径之外

模型

  • 图像
  • 视频
  • Nano Banana 2.1
  • GPT Image 2.6
  • Kling 4.0
  • Product Attributes
  • 全部模型

路径

  • 供应商直连 API
  • 合作网关
  • 自有 NPU
  • 自带密钥

开发者

  • API 参考
  • Agent 提示词
  • llms.txt
  • Webhook

资源

  • 文档
  • 请求生命周期
  • 文件

公司

  • 联系我们
  • 获取 API 密钥
一个密钥所有模型
队列优先请求不丢弃
只切换到同一模型不暗中替换
路由可见served_by + attempts
签名 WebhookStandard Webhooks
每次请求的成本已记录
© 2026 Rawswitch
服务条款隐私政策
预览版

Kling 4.0 Reference to Video

Kling (Kuaishou)视频生视频已上线
SchemaAPI 文档
kling/kling-4.0-reference-to-video
视频生成图生视频参考生视频视频编辑
$0.24675 / 秒 · 1080p
可商用供应商条款
在线体验API

1. 调用 API

  • 获取 API 密钥
  • 提交请求

2. 认证

  • API 密钥

3. 队列

  • 请求生命周期
  • 查询请求状态
  • 流式获取状态
  • 获取结果
  • 取消请求

4. 文件

  • 上传文件

5. Webhook

  • 签名 Webhook

6. Schema

  • 输入
  • 输出

7. Agent

  • Agent 提示词

简介

Generates a 3–30 second video guided by reference images at 720p, 1080p or 4k.

1. 调用 API

获取 API 密钥#

密钥以 rsw_ 开头,仅在创建时显示一次。请把密钥保存在服务器上,并通过环境变量 RAWSWITCH_API_KEY 提供给代码。

export RAWSWITCH_API_KEY="rsw_live_…"

提交请求#

所有模型都响应同一个端点。请求体是统一的外层结构:model 选择模型,input 承载该模型自己的字段,webhook、route 和 tags 为可选。

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-reference-to-video",
    "input": {
      "prompt": "The person from @Image1 walks through a sunlit market holding the mug from @Image2",
      "image_urls": [
        "https://files.rawswitch.example/samples/model-front.jpg",
        "https://files.rawswitch.example/samples/mug.jpg"
      ],
      "duration": 5
    }
  }'

请求被接受并进入队列。你会拿到请求 ID 和用于跟踪状态的 URL。

{
  "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"
  }
}

2. 认证

API 密钥#

在 Authorization 请求头中以 Bearer 令牌形式发送密钥。没有有效密钥的调用会以 error.type = "authentication_error" 失败。

Authorization: Bearer $RAWSWITCH_API_KEY
不要带着密钥从浏览器直接调用 API。请在前面放一个小型服务端路由。

3. 队列

请求生命周期#

请求依次经过 queued → running → succeeded、failed 或 canceled。短任务可以让提交调用等待:它会返回在时限内到达的状态。

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.json
每次提交都发送 Idempotency-Key,重试时使用同一个值。否则重试的请求可能再次运行并重复计费。

查询请求状态#

一次调用即可拿到状态,完成后还会一并返回输出。

curl https://rawswitch.ai/v1/requests/req_01JDF3K8Q2 \
  -H "Authorization: Bearer $RAWSWITCH_API_KEY"

流式获取状态#

通过服务器发送事件(SSE)实时跟踪请求,无需反复轮询。

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 是生成输出的路径名称,attempts 列出所有尝试过的路径。路由过程没有任何隐藏。

{
  "id": "req_01JDF3K8Q2",
  "model": "kling/kling-4.0-reference-to-video",
  "status": "succeeded",
  "output": {
    "videos": [
      {
        "url": "https://files.rawswitch.example/req_01JDF3/kling-4.0-reference-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"

4. 文件

上传文件#

输入接受 URL。公开 URL 可以直接使用。本地文件需先获取上传 URL,把文件发送过去,再传入返回的 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.jpg

5. Webhook

签名 Webhook#

在请求中加入 webhook,Rawswitch 会在请求完成后把结果 POST 到你的 URL。投递按 Standard Webhooks 规范签名,你的端点失败时会重试。

{
  "model": "kling/kling-4.0-reference-to-video",
  "input": {},
  "webhook": {
    "url": "https://your-app.example/hooks/rawswitch"
  }
}

6. Schema

输入#

字段类型必填说明
promptstring是What happens in the video. Refer to reference images as @Image1, @Image2, …
image_urlsstring[] (URL)—Up to 10 images whose subjects or look the video should keep, in order (@Image1, @Image2, …).最多 10 个。
image_urlstring (URL)—Optional first frame. Counts toward the image limit.
middle_image_urlsstring[] (URL)—Up to 8 frames to pass through between the start and the end, in order. They count toward the image limit.最多 8 个。
end_image_urlstring (URL)—Optional last frame. The video moves from the start image to this one.
durationinteger—Length of the video in seconds (3–30). Billed per second.默认值 5。
resolutionenum—Output resolution. Higher resolutions cost more per second.可选值:720p, 1080p, 4k。默认值 "1080p"。
hdrboolean—10-bit HDR instead of SDR. Only at 1080p and 4k, billed per second on top of the base price.默认值 false。
aspect_ratioenum—Shape of the video frame. "auto" follows the references.可选值:auto, 16:9, 9:16, 1:1, 4:3, 3:4, 21:9。默认值 "16:9"。

输出#

生成的视频在 output.videos 中:每个视频一项,包含 url、content_type 和 bytes;能从文件读出时还包含 width、height 和 duration_seconds。

字段类型说明
videosarrayGenerated 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-reference-to-video-0.mp4",
      "content_type": "video/mp4",
      "bytes": 4821933,
      "width": 1280,
      "height": 720,
      "duration_seconds": 5
    }
  ]
}

此模型背后的路径:

  • partner/gateway — 合作网关 (主用)

7. Agent

Agent 提示词#

粘贴到编程 Agent 中。其中包含端点、Schema,以及安全调用此模型的规则。

Agent 提示词 · kling/kling-4.0-reference-to-video
You are adding the Rawswitch model `kling/kling-4.0-reference-to-video` (Kling 4.0 Reference to Video — reference to video) to this codebase.

## What it does
Generates a 3–30 second video guided by reference images 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-reference-to-video",
  "input": {
    "prompt": "The person from @Image1 walks through a sunlit market holding the mug from @Image2",
    "image_urls": [
      "https://files.rawswitch.example/samples/model-front.jpg",
      "https://files.rawswitch.example/samples/mug.jpg"
    ],
    "duration": 5
  }
}
```

## Input fields
- `prompt` (string, required): What happens in the video. Refer to reference images as @Image1, @Image2, …
- `image_urls` (array of URLs, at most 10 items): Up to 10 images whose subjects or look the video should keep, in order (@Image1, @Image2, …).
- `image_url` (URL): Optional first frame. Counts toward the image limit.
- `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.
- `aspect_ratio` (string, one of "auto", "16:9", "9:16", "1:1", "4:3", "3:4", "21:9", default "16:9"): Shape of the video frame. "auto" follows the references.

## 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-reference-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.

示例中的基础 URL https://rawswitch.ai 是域名确定前的占位值。