Generate images, video and audio in coding agents
Generate images, video and audio from Codex, Claude Code, Cursor or Cline. Keep a text model as the main model and call media models through BigModel.io's MCP server (https://bigmodel.io/mcp) or an AGENTS.md note.
A coding agent's main model must be a text model: it has to chat and call tools. Image, video and audio models only produce content, so they cannot be the main model; picking one in the model selector fails.
Instead, let the text model call the media models. Two ways:
| Way | How | For |
|---|---|---|
| MCP server (recommended) | Add https://bigmodel.io/mcp to the agent; it gains tools such as generate_image and generate_video |
Tools that support MCP: Codex, Claude Code, Cursor, Cline, Cherry Studio and more |
| AGENTS.md note | Describe the endpoints and commands in the project instructions; the agent runs curl itself |
Agents that run commands but where MCP is inconvenient |
Both use your own API key and are billed exactly like the API: images per image, video per second, audio per request or duration. Prices are on the models page.
#Way 1: MCP server
The server is https://bigmodel.io/mcp and authenticates with your API key (Authorization: Bearer <your key>). Set BIGMODEL_API_KEY in your shell first.
#Codex
Add to ~/.codex/config.toml:
[mcp_servers.bigmodel]
url = "https://bigmodel.io/mcp"
bearer_token_env_var = "BIGMODEL_API_KEY"
tool_timeout_sec = 300Videos usually take 1–3 minutes; a longer tool_timeout_sec lets the tool wait for the result.
#Claude Code
claude mcp add --transport http bigmodel https://bigmodel.io/mcp \
--header "Authorization: Bearer $BIGMODEL_API_KEY"#Cursor
Add to ~/.cursor/mcp.json (or .cursor/mcp.json in the project):
{
"mcpServers": {
"bigmodel": {
"url": "https://bigmodel.io/mcp",
"headers": { "Authorization": "Bearer ${env:BIGMODEL_API_KEY}" }
}
}
}Other tools that support Streamable HTTP MCP servers take the same URL and header.
#Tools
| Tool | What it does |
|---|---|
list_media_models |
Lists the image, video and audio models you can use, with prices; call it first |
generate_image |
Makes 1–4 images from a prompt and returns links |
generate_video |
Makes a video, optionally from a start image; waits up to wait_seconds (default 50, max 240) and otherwise returns the task ID |
get_video |
Checks a video task and returns the link when done |
generate_audio |
Makes music or sound; model-specific fields go in options |
get_audio |
Checks an audio task |
Links are valid for 24 hours. Have the agent download them into the project with curl -L -o <file> <link>, for example:
Use BigModel to make a 1024x1024 flat-illustration app icon and download it to
assets/icon.png.
#Way 2: AGENTS.md note
Put this in AGENTS.md at the project root (CLAUDE.md for Claude Code); the agent runs the commands itself.
## Generating images, video and audio
Use BigModel.io. The key is in the environment variable `BIGMODEL_API_KEY`; never write it into code or commit it.
Result links are valid for 24 hours: download them into the project right away.
- Models: `curl -s "https://bigmodel.io/v1/models?type=all" -H "Authorization: Bearer $BIGMODEL_API_KEY"`; use models whose `architecture.modality` is image, video or audio.
- Image (returns when done):
```bash
curl -s https://bigmodel.io/v1/images/generations \
-H "Authorization: Bearer $BIGMODEL_API_KEY" -H "Content-Type: application/json" \
-d '{"model":"<image model>","prompt":"<description>","size":"1024x1024","n":1}'
```
Download `data[0].url`: `curl -L -o assets/<name>.png "<url>"`.
- Video (async task):
```bash
curl -s https://bigmodel.io/v1/videos \
-H "Authorization: Bearer $BIGMODEL_API_KEY" -H "Content-Type: application/json" \
-d '{"model":"<video model>","prompt":"<description>","seconds":5}'
```
Poll `GET https://bigmodel.io/v1/videos/<id>` every 10 seconds until `status` is `succeeded`, then download `output.url`. `failed` is not charged.
- Audio (async task): `POST https://bigmodel.io/v1/audio/generations`, used like video; poll `GET /v1/audio/generations/<id>`.
- Tell me the estimated cost before generating (prices: https://bigmodel.io/models); ask me first if it is over $1.#Troubleshooting
Picked an image or video model in the model selector and got model_endpoint_mismatch. Switch the main model back to a text model and use the tools above for media.
The MCP tools return 401. The agent did not get BIGMODEL_API_KEY, or the header does not carry the key.
The video stays "still running". Videos can take a few minutes. Ask the agent to call get_video later, or raise wait_seconds and the tool timeout.
Insufficient balance. Video is billed per second and the balance has to cover the estimate when you submit. Top up.
#Related
Updated · View as Markdown