🎉 每个积分包首次购买都有免费生成好礼 —— 最高 20 个 Lite 视频 + 20 张 Lite 图片 + 10 个 Medium 视频 + 10 张 Pro 图片 + 2 个 Pro 视频。

立即开始

Claude Code 现在可以生成图像了

Claude Code 已经可以编辑你的代码。借助 DreamUtopia REST API,同一个会话可以创建主视觉图片、重新设计产品图,或将静态图片变成八秒钟的视频。粘贴一个技能文件,用平实的英语提出请求,智能体就会处理上传、请求和轮询。

从实际示例开始

这些是本页示例所使用的提示词。打开生成器,选择一个示例,然后逐一调整细节。

把这个厨房台面变成一个舒适的秋日场景。保留白色马克杯和木质台面,加入散落的肉桂棒、一块亚麻布,以及更温暖的低角度阳光。

示例提示词 01

把这个厨房台面变成一个舒适的秋日场景。保留白色马克杯和木质台面,加入散落的肉桂棒、一块亚麻布,以及更温暖的低角度阳光。

将这片高山湖泊绘制成松散的水彩画。保留山峰和倒影,柔化松树,并让晨光更温暖。

示例提示词 02

将这片高山湖泊绘制成松散的水彩画。保留山峰和倒影,柔化松树,并让晨光更温暖。

将这家面包店店面重绘为一张插画明信片。保留招牌、橱窗陈列和人行道,并使用干净的墨线和温暖的夜晚色调。

示例提示词 03

将这家面包店店面重绘为一张插画明信片。保留招牌、橱窗陈列和人行道,并使用干净的墨线和温暖的夜晚色调。

Claude Code 图像生成,无需离开终端

当代理能够直接调用媒体 API 时,Claude Code 图像生成就成为编码会话的正常组成部分。编码代理擅长运行命令、读取响应并进行智能重试,而这正是媒体 API 所需要的。你不必离开终端去打开 Web 应用,而是可以向 Claude Code 请求一张 16:9 的页眉图片,并在同一对话中拿回结果 URL。正因如此,我们将 DreamUtopia API 构建为纯 REST。无需配置 MCP 服务器,也无需安装插件。该技能文件教会代理基础 URL、身份验证标头、multipart 上传、两个创建端点、轮询循环以及错误规则。粘贴一个技能并设置一个环境变量就是全部设置。同一个密钥也可用于你自己的脚本,这意味着代理和你的构建流水线共享同一套集成和同一个额度余额。当设计任务从聊天开始、在部署脚本中结束时,这一点很重要:两者之间的请求形态不会改变。该工作流也契合编码代理已有的工作方式:请求是普通的 shell 命令,失败是普通的 HTTP 状态,长时间运行的任务是普通的待轮询 id。这意味着 Claude Code 可以用它解释失败测试时同样的语气来解释失败,并且可以将生成的资源放在引用它的代码旁边。对于设计密集型仓库,这一差异是实用性的而非表面性的:编写组件的人也是能够生成其所需图像的人,无需切换工具或丢失更改的上下文。由于同一个密钥同时覆盖静态图像和动态影像,团队可以为两者保留一套集成和一个余额,代理可以将完成的图像直接串联到下一个片段请求中。

你会得到什么

一项复制粘贴技能

将下面的技能块粘贴到 Claude Code 聊天中。智能体会在接下来的对话中按照该配方执行,无需额外提示。文本足够简短,可以一口气读完,并且足够具体,智能体不会自行臆造字段名。它明确说明每个字段接受的确切值,因此格式错误的请求在到达 API 之前就会被纠正。不会向你的代码仓库写入任何内容,也不会安装任何东西。

本地文件已处理

智能体会通过 multip 请求上传你项目中的一张照片,然后将返回的 id 传入生成流程。JPEG、PNG 和 WebP 格式的上限为 30 MB。存放在代码仓库中的文件无需先获得公开 URL。

图像和视频,一个密钥

文生图、图生图、文生视频、图生视频以及首尾帧过渡都使用同一个密钥和同一个积分余额。你无需为静态图像和动态视频分别管理账户,并且该技能可以将一张已完成的图像串联到下一个视频请求中。

比聊天更持久的职位

每次生成都在我们的服务器上运行。如果会话结束,代理可以按 ID 列出最近的任务,并在之后收集结果。签名后的结果链接在七天内保持有效,这足够下载结果或将其复制到构建产物中。

通俗英语请求

请求生成方形产品图或竖版社交短视频。该技能会将你的描述映射到模型、分辨率、时长和宽高比,然后在消耗额度之前检查实时价格矩阵。当任务需要时,你仍然可以指定确切的设置。智能体会将所选的设置回报给你,这使得意外结果更容易排查。

一份价格表

API 和 Web 应用扣除相同的积分。GET /v1/models 返回实时的分辨率、时长和积分矩阵,因此代理可以在创建任何内容之前比较五秒片段与十秒片段。

工作原理

1

创建并导出密钥

打开 Profile,然后进入 API keys,创建一个有名称的密钥。在启动 Claude Code 的 shell 中将其导出为 DREAMUTOPIA_API_KEY。密钥仅对付费账户可用,仅显示一次,并且可以在不影响其他集成的情况下撤销。

2

粘贴技能

复制下面的块并粘贴到 Claude Code 聊天中。代理随后便知道该对话的端点、字段名称和轮询规则。该技能还说明了不应做什么:不要重试被拒绝的任务,也不要把密钥粘贴到对话中。在新的会话中重复粘贴;不会向你的仓库添加任何内容。

3

说出你需要什么

写一个普通请求:生成一张雪中红狐的2K图像,或者把 ./photo.png 转成一段带有缓慢推镜的720p短片。智能体会自行选择设置,可以先检查 /v1/models,并在源文件为本地文件时处理上传。如果请求含糊不清,它会简短地问一个问题,而不是去猜测时长或宽高比。

4

投票并使用结果

代理会轮询 GET /v1/generations/{id},直到任务成功,然后返回带签名的结果 URL。它在轮询之间进行退避,并在遇到终止性失败时停止,而不是对内容策略拒绝或已耗尽的信用余额进行重试。最终答案同时包含任务 id 和链接,因此即使对话已不存在,结果也能再次被找到。

将 DreamUtopia Skill 粘贴到 Claude Code 中

复制下面的技能,并粘贴到 Claude Code 聊天中。此后在整个对话过程中,该智能体就能了解 API 接口、错误规则以及何时不应重试。

Paste into Claude Code
Download
> Paste this into the Claude Code chat. It teaches the agent the DreamUtopia API for the
> rest of the conversation. Keep the `DREAMUTOPIA_API_KEY` in your shell environment,
> not in the pasted text.

# DreamUtopia media generation

Use this skill when the user asks you to generate an image or a video with DreamUtopia.

## Prerequisites

- **API access requires a paid account.** Keys cannot be minted by a free account.
- The user sets their key in the environment:

  ```sh
  export DREAMUTOPIA_API_KEY="du_live_..."
  ```

  If `DREAMUTOPIA_API_KEY` is unset, **stop and ask the user to set it**. Never write the key
  into a project file, a commit, or a message.
- Base URL: `https://api.dreamutopia.net/v1`
- Every request sends `Authorization: Bearer $DREAMUTOPIA_API_KEY`.

## Keeping this skill current

This skill is served by the product and can change without notice. If a request fails in a way
this document does not describe — an unknown field, an unexpected status or error code, or a
route that returns `404` — the skill may be stale. Re-fetch it, paste the new version into the
conversation, and re-read it before retrying:

```sh
curl -fsSL https://dreamutopia.net/skills/dreamutopia/claude-code.md
```

Do not invent request fields from memory. The re-fetched file is the current contract; the copy
in the conversation is only a snapshot.

## 1. Upload a local reference image (optional)

Only needed when the user has a local file. A previous generation's `result.url` can be used
directly instead.

```sh
curl -sS -X POST https://api.dreamutopia.net/v1/uploads \
  -H "Authorization: Bearer $DREAMUTOPIA_API_KEY" \
  -F "file=@/path/to/photo.png"
```

Response `201`:

```json
{ "id": "<upload_id>",
  "url": "<upload_url>",
  "expires_at": "2026-10-31T12:00:00Z" }
```

Use `id` (not `url`) in the next request. Accepted: JPEG, PNG, WebP, up to 30 MB.
`id` only works for the account that uploaded it.

## 2. Create an image

```sh
curl -sS -X POST https://api.dreamutopia.net/v1/images/generations \
  -H "Authorization: Bearer $DREAMUTOPIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "lite",
    "prompt": "a red fox in fresh snow, cinematic",
    "resolution": "2k",
    "aspect_ratio": "1:1"
  }'
```

| Field | Values |
|---|---|
| `model` | `lite`, `pro` |
| `resolution` | `2k`, `4k` (`lite` accepts `2k` only) |
| `aspect_ratio` | `1:1`, `4:3`, `3:4`, `16:9`, `9:16`, `3:2`, `2:3`, `adaptive` |
| `reference_images` | array of upload ids or DreamUtopia URLs; 0–3 for `lite`, 0–14 for `pro` |
| `prompt` | non-empty, up to 8000 characters |

`adaptive` requires at least one reference image. `resolution` defaults to `2k` and
`aspect_ratio` to `1:1`.

Response `202`:

```json
{ "id": "3f2b…", "type": "image", "status": "queued", "created_at": "2026-10-24T12:00:00Z" }
```

## 3. Create a video

```sh
curl -sS -X POST https://api.dreamutopia.net/v1/videos/generations \
  -H "Authorization: Bearer $DREAMUTOPIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "medium",
    "prompt": "the fox turns and looks at the camera",
    "image": "<upload_id>",
    "resolution": "720p",
    "duration": 8
  }'
```

| Field | Values |
|---|---|
| `model` | `lite`, `medium`, `pro` |
| `resolution` | `480p`, `720p`, `1080p` (`lite` cannot use `1080p`) |
| `duration` | 5–10 seconds (`lite`), 5–15 (`medium`), 5–30 (`pro`) |
| `image` | first-frame upload id or DreamUtopia URL (omit for text-to-video) |
| `last_frame_image` | requires `image`; not supported by `lite` |
| `generate_audio` | `pro` only, and the account must hold premium; `lite` and `medium` are rejected |

Response `202` with `type: "video"`.

## 4. Poll until it finishes

```sh
curl -sS https://api.dreamutopia.net/v1/generations/$MID \
  -H "Authorization: Bearer $DREAMUTOPIA_API_KEY"
```

`status` is one of `queued`, `processing`, `succeeded`, `failed`.

- Poll every 3–5 seconds, backing off to 10 seconds. Give up after about 10 minutes.
- On `succeeded`, download `result.url`. The link is valid for 7 days.
- On `failed`, report `error.message` to the user and stop. A failed job is terminal; do
  **not** submit it again automatically.
- If an id is lost, `GET /generations?limit=20` lists recent jobs, newest first.

Terminal response:

```json
{
  "id": "3f2b…",
  "type": "video",
  "status": "succeeded",
  "model": "medium",
  "credits_used": 12,
  "created_at": "2026-10-24T12:00:00Z",
  "updated_at": "2026-10-24T12:02:10Z",
  "result": { "url": "<result_url>" },
  "error": null
}
```

## 5. Check credits and prices

```sh
curl -sS https://api.dreamutopia.net/v1/account -H "Authorization: Bearer $DREAMUTOPIA_API_KEY"
curl -sS https://api.dreamutopia.net/v1/models
```

`/models` is public and returns every tier's allowed resolutions and durations plus the
`resolution → duration → credits` matrix. Check it before choosing settings when the user
cares about cost.

## Errors

Every error body is exactly:

```json
{ "error": { "code": "insufficient_credits", "message": "You need more credits to generate." } }
```

| HTTP | Meaning |
|---|---|
| 400 | invalid input (`invalid_request`, `prompt_too_long`, `invalid_reference_image`, …) |
| 401 | missing, malformed, revoked or removed-account key |
| 402 | not enough credits |
| 403 | unpaid key creation, or audio requested without premium |
| 404 | unknown job, or a job belonging to another account |
| 409 | `Idempotency-Key` reused with a different body, or still in flight |
| 413 / 415 | upload too large / not a supported image |
| 429 | rate limited; read `Retry-After` |
| 500 / 503 | internal; retry later |

Retry only HTTP `429`, `timeout` and `internal` responses. Never retry
`insufficient_credits`, and never resubmit a job that already finished as `failed`.

## Idempotency

Send `Idempotency-Key: <unique value>` on a create request. A retry with the same key and
body returns the existing job (`200`) instead of creating and charging a second one. Use a
fresh value for every genuinely different request.

## Complete example

```sh
#!/usr/bin/env bash
set -euo pipefail
: "${DREAMUTOPIA_API_KEY:?set DREAMUTOPIA_API_KEY first}"
API="https://api.dreamutopia.net/v1"

ID=$(curl -sS -X POST "$API/images/generations" \
  -H "Authorization: Bearer $DREAMUTOPIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"lite","prompt":"a red fox in fresh snow","resolution":"2k","aspect_ratio":"1:1"}' \
  | jq -r .id)

while :; do
  BODY=$(curl -sS "$API/generations/$ID" -H "Authorization: Bearer $DREAMUTOPIA_API_KEY")
  STATUS=$(jq -r .status <<<"$BODY")
  case "$STATUS" in
    succeeded) jq -r .result.url <<<"$BODY"; break ;;
    failed)    jq -r .error.message <<<"$BODY" >&2; exit 1 ;;
    *)         sleep 4 ;;
  esac
done
```

探索相关工具

选择适合你下一步创作的工具。

常见问题

由DreamUtopia团队 · 更新于 2026年11月15日

使用Claude Code时,我需要MCP服务器才能使用DreamUtopia吗?

▼
不。该 API 是纯 HTTP 的,该技能教 Claude Code 使用 curl 调用它。你不需要 MCP 服务器、CLI 二进制文件或插件。唯一的设置是粘贴该技能和环境变量。

API 密钥应该放在哪里?

▼
在shell环境中设为DREAMUTOPIA_API_KEY。不要将其放入粘贴的技能、仓库和提示词中。该技能会让智能体在变量缺失时停下并询问,从而避免发出配置不完整的请求。

Claude Code 能上传本地图片吗?

▼
是的。让它使用项目中的文件。代理会发送一个 multipart 上传,接收一个上传 id,并在生成中使用该 id。接受 JPEG、PNG 和 WebP,最大 30 MB。

该技能既能生成视频,也能生成图像吗?

▼
是的。同一个密钥涵盖文生视频和图生视频,时长从五秒到十五秒不等,具体取决于模型档位。首尾帧过渡在较高档位可用。

积分是如何扣除的?

▼
任务创建时会扣除积分,若失败则退还。实时价格矩阵位于 GET /v1/models,当你询问费用时,该技能会检查它。在创建密钥之前,需要拥有付费账户。

如果我关闭会话会发生什么?

▼
任务会在我们的服务器上继续运行。使用 GET /v1/generations/{id} 并传入 id,或使用 GET /v1/generations?limit=20 列出最近的任务。签名结果 URL 有效期为七天。

撤销密钥安全吗?

▼
可以。撤销会立即阻止新请求,但不影响正在运行的任务。一个账户可以持有多个密钥,因此可以停用某个集成而不影响其他集成。

给 Claude Code 一个媒体工具

创建密钥,粘贴技能,然后请求你的第一张图像。API 文档涵盖了每个字段、状态和错误代码。