宇宙生成 API
用你自己的代码做视频。Studio 里智能体用的每个工具,都是一次 HTTPS 调用,积分和规则都和 Studio 一样。
要连接 ChatGPT、Claude 或别的智能体? 你不需要这一页。把 https://mcp.cosmomaker.ai/mcp 给它,或者在个人资料页的“已连接的智能体”里按步骤连接。
你的密钥
在个人资料页的“API 密钥”里点“创建 API 密钥”。密钥只显示这一次,请妥善保存。每次调用都带上它:
Authorization: Bearer cm_…
每个密钥有自己的规则,随时可以在“管理”里修改:每天不经询问能花多少积分、能看到哪些工作流,以及能不能自己开始渲染。
调用工具
把工具的参数以 JSON 格式 POST 到这个工具的地址:
curl https://api.cosmomaker.ai/v1/tools/create_workflow \
-H "Authorization: Bearer $COSMOMAKER_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Paper boat"}'每个回答都有同样的两个字段:text 是文字形式的回答,ids 按顺序列出回答里提到的每个 id。
{"text": "made wf_a8e7b371 \"Paper boat\": 16:9, 720P",
"ids": ["wf_a8e7b371"]}id 的开头说明它是什么:wf_ 是工作流,pic_ 是图片,vid_ 是素材库里的视频,take_ 是渲染出的一条视频,job_ 是一项渲染任务。
耗时的工作
图片、预览和渲染要几秒到几分钟。40 秒后还没做完的调用会返回 202 和它的 call id。把它交给 wait:调用结束时它就回答,或者等满 up_to 秒再回答(还没做完时再次返回 202):
POST /v1/tools/wait {"ids": "call_5c0e1f2a", "up_to": 80}要跟进一个工作流上的所有工作(包括渲染),就改传这个工作流。它回答 nothing is under way 时,一切都完成了。
POST /v1/tools/wait {"workflow": "wf_a8e7b371", "up_to": 80}
{"text": "job_81289cac: the take landed, take_bb6c5a36",
"ids": ["job_81289cac", "take_bb6c5a36"]}发送文件
upload_file 会给你一个一次性链接。把文件发到这个链接,再把它加进工作流的素材库:
POST /v1/tools/upload_file {"name": "script.md", "type": "text/markdown", "size": 18234}
PUT <the link in its answer> the file's bytes
POST /v1/tools/add_to_library {"workflow": "wf_a8e7b371", "url": "<the url in its answer>"}图片和音频最大 10 MB,文档(.md、.txt、.docx、.doc、.pdf)最大 50 MB,视频最大 2 GB。
积分和限额
quote在开始之前给出准确的价格,不会改动任何东西。- 你的改动先进草稿。如果密钥有权限,
land会把草稿放到工作流上并开始渲染;没有权限时,由你在 Studio 里点“使用这些改动”。 - 在密钥每日限额内的工作会马上开始;超出限额的,要等你在 Studio 里点“开始”。
whoami显示你的积分、今天的限额还剩多少,以及这个密钥能做什么。
出错时
调用失败时,会返回 HTTP 状态码和文字说明的原因:
{"error": {"type": "invalid_request_error",
"message": "S1 has no reference picture, so the take can't start: …"},
"request_id": "9b1c2f…"}400 | 工具拒绝了,或者请求体不是工具的参数。消息会说明原因和下一步怎么做。 |
401 | 密钥不对,或者已被删除。 |
403 | 密钥已暂停;或者这是应用登录得到的通行证,它只能用在智能体的地址上。 |
404 | 没有这个名字的工具。 |
429 | 每秒超过 10 次调用。稍等一下再试。 |
一个完整的视频
从零到一个 MP4,用 Python 和 requests:
import requests
API = "https://api.cosmomaker.ai/v1/tools/"
KEY = {"Authorization": "Bearer cm_…"}
def call(tool, **args):
r = requests.post(API + tool, json=args, headers=KEY, timeout=150)
r.raise_for_status()
while r.status_code == 202: # still going: wait for it
r = requests.post(API + "wait", json={"ids": r.json()["call"]}, headers=KEY, timeout=150)
r.raise_for_status()
return r.json()
wf = call("create_workflow", name="Paper boat")["ids"][0]
call("add_segments", workflow=wf, count=1, seconds=5)
# a scene is filmed from a picture of its place or its people
pic = call("make_picture", workflow=wf,
words="A red paper boat on a rainy street puddle at dusk, no people")["ids"][0]
call("add_to_bible", workflow=wf, kind="place", name="Rainy street", picture=pic)
call("set_references", workflow=wf, segment="S1", cast="@Rainy street")
# our cinematographer writes the scene from a note
call("write_segment", workflow=wf, segment="S1",
note="The boat drifts across the puddle.", shots="0-5 s: wide, slow push in")
print(call("quote", workflow=wf)["text"]) # the price, before anything starts
call("shoot", workflow=wf)
call("land", workflow=wf) # the key must be allowed to start renders
while "nothing is under way" not in call("wait", workflow=wf, up_to=80)["text"]:
pass
take = [i for i in call("open_workflow", workflow=wf)["ids"] if i.startswith("take_")][0]
print(call("deliver", workflow=wf, take=take)["text"]) # the MP4's link工具
共 49 个,打开本页时从 GET /v1/tools 读取,所以列表总和 API 一致。每个工具的说明就是智能体读到的英文原文。
whoamiYour credits, what's left of today's limit, the workflows you can see, and whether your changes land without Use.
没有参数。
list_workflowsThe workflows you can see, newest first: id, name, scenes, takes.
querystring可选- words in the name
create_workflowA new workflow. It joins the ones you can see. Free.
namestring- its name
orientationstring可选- landscape unless asked (portrait, landscape)
resolutionstring可选- 720P unless asked (480P, 720P)
speech_languagestring可选- the language its spoken lines are in
likestring可选- a wf_ id: its settings, and with cast its people and places, come along
caststring可选- with like: the people and places to carry over, by name with commas
copy_workflowA private copy of a workflow: its scenes, cast, library and takes, on the same files. It joins the ones you can see. Free.
workflowstring- a wf_ id
namestring可选- its name; the old name and (copy) if left out
find_resourcesSearch everything in the workflows you can see, by words, kind, who made it or where it is: pictures, audio, videos, documents, and the people and places of their bibles. Each with its id, its workflow, what uses it, who made it and its link.
querystring可选- words in its name or prompt
kindstring可选- (picture, audio, video, document, bible)
workflowstring可选- a wf_ id: only there
made_bystring可选- agents: only what an agent made (agents)
upload_fileA one-time link to send a file from your disk straight to our bucket, which costs you no tokens: run its curl line, then add_to_library. Pictures and audio up to 10 MB, documents (.md, .txt, .docx, .doc, .pdf) 50 MB, video 2 GB.
namestring- the file's name, with its extension
typestring- its content type, e.g. text/markdown, image/png
sizeinteger- its exact size in bytes
get_guideHow to write for the models and work the Studio, by topic. Call it with no topic for the list.
topicstring可选- (words, crew, bible, pictures, frames, checking, editing, music)
open_workflowThe workflow as you would change it, your draft's changes in it: its settings, cast and places, every scene with its id, length, price and the start of its words, the library's newest, the Sound lane, the takes. look reads a scene whole.
workflowstring- a wf_ id
previzA 480P test of one scene, from your draft: 0.55 credits for 10 s with 2 pictures. Within the creator's daily limit it starts at once, above it the creator gets a Go card. wait follows it, then look at it by its job_ id.
workflowstring- a wf_ id
segmentstring- a scene: S2 (its place now) or seg_ab12cd34
set_wordsOnly for words the creator gave you exactly (else write_segment: our cinematographer writes them). Puts a scene's whole words into the draft; they are checked as the cinematographer's are, and an error says what to fix. get_guide words has the format. Set its references first, so its labels answer.
workflowstring- a wf_ id
segmentstring- a scene: S2 (its place now) or seg_ab12cd34
wordsstring- the exact text the video model reads
shotsstring可选- its shot plan: '0-5 s: wide, still: what is seen; 5-10 s: close-up: ...'; every scene is shot from one, so it's needed when it has none or this reframes or retimes a shot
copy_bibleCarry people and places from another workflow into this one's bible, in the draft, by name, with their pictures, looks and voices, on the same files. Only who is on that workflow: who is only in a draft comes with Use.
workflowstring- a wf_ id
frmstring- a wf_ id: the workflow they are in
namesstring- their names, with commas
add_to_libraryAdd a file to this workflow's library: an upload_file url once its curl has run, or a small file inline (a picture or a document, under 1.5 MB).
workflowstring- a wf_ id
urlstring可选- the url upload_file gave
namestring- what to call it, with its extension
content_base64string可选- the file's bytes
typestring可选- with content_base64: its content type
copy_resourcesPut library items of other workflows into this one's library: the same files, new rows.
workflowstring- a wf_ id
idsstring- pic_, aud_, vid_ and doc_ ids with commas
remove_resourceTake a library item off this workflow, only one you made. What the creator made or uploaded stays: ask them.
workflowstring- a wf_ id
idstring- a pic_, aud_, vid_ or doc_ id you made
build_editMake a new take from a saved take's Edit lane: its cuts, look, captions and transitions, as the creator's Build button does. Free. The take stays as it is. Answers with a job id.
workflowstring- a wf_ id
sayPut a line in the dock for the creator to read in Studio: what you are doing, or what you need.
workflowstring- a wf_ id
textstring- one short line
proposeHand the draft to the creator: they see your changes and renders in Studio, with a Use button and a Discard button, and your message. wait with this workflow follows their answer.
workflowstring- a wf_ id
messagestring可选- what you did and what you ask of them, a sentence or two
landLand the draft on the workflow yourself, only if the creator allowed it (whoami says so). Renders within the daily limit start, the rest wait for their Use.
workflowstring- a wf_ id
add_segmentsAdd empty scenes to the draft. Give them words with write_segment: our cinematographer writes them.
workflowstring- a wf_ id
countinteger- how many, 1-20
afterstring可选- the scene to add them after; S0 puts them first; left out: at the end
secondsinteger可选- each one's length, 5-15
modestring可选- what they render from (omni_reference, first_last_frame)
continuesboolean可选- true: each carries on from the scene before it, with no cut
set_segmentChange a scene's length, mode, continuity or place in the order, in the draft. Pass only what changes.
workflowstring- a wf_ id
segmentstring- a scene: S2 (its place now) or seg_ab12cd34
secondsinteger可选- 5-15
modestring可选- (omni_reference, first_last_frame)
continuesboolean可选- true: no cut from the scene before
move_tointeger可选- new position, 1 = first
remove_segmentRemove a scene from the draft. The ones after it move up.
workflowstring- a wf_ id
segmentstring- a scene: S2 (its place now) or seg_ab12cd34
write_screenplayHave our screenwriter write a story as a screenplay document in the library: scenes of 5-15 s with every line. Or change a script in the library, the rest kept word for word. Skip it when the creator has a script: upload that.
workflowstring- a wf_ id
briefstring- what the creator asks, word for word
secondsinteger可选- how long the whole video is, in seconds
episodesinteger可选- how many episodes
scriptstring可选- a doc_ id: the script to change; left out, a new story
pitchboolean可选- true: two loglines to choose from, nothing saved
script_onlyboolean可选- true: the creator wants only the script for now
write_segmentHave our cinematographer write a scene's whole words, the exact text the video model reads, from the scene as it is, its shot plan and your note, into the draft. Set its references first. For a whole script use break_down_script.
workflowstring- a wf_ id
segmentstring- a scene: S2 (its place now) or seg_ab12cd34
notestring- what it shows, in the creator's words: every fact, act, line, camera note and timing; for a change, only what changes
shotsstring可选- its whole shot plan: '0-5 s: wide, eye level, still: what is seen; 5-10 s: close-up, slow push-in: ...'; needed when it has none or the change reframes or retimes a shot
set_referencesSet what a scene renders from, in the draft: who is in it, each on their bible picture, and its other pictures, videos and clips (omni reference), or its first and last frame (first/last frame).
workflowstring- a wf_ id
segmentstring- a scene: S2 (its place now) or seg_ab12cd34
caststring可选- who is in it, by bible name in the order its words number them, e.g. '@Mia, @Kitchen'; 'none' clears them
picturesstring可选- its other references in order, pic_, vid_ and aud_ ids with commas: 9 pictures, 3 videos and 3 clips at most, a video 2 s at least; 'pic_ab12cd34:composition' lends framing, light or things only; '' clears them
mutestring可选- vid_ ids among them whose own sound is off; '' turns all sound on
firststring可选- a pic_ id, or 'none'
laststring可选- a pic_ id, or 'none'
add_to_bibleAdd a person or place to the series bible in the draft, or change one, by name.
workflowstring- a wf_ id
kindstring- (person, place)
namestring- their name
lookstring可选- one sentence in the creator's language: a person's age (an adult), hair, face, build, clothes; a place's look and light
pronounstring可选- (she, he)
picturestring可选- a pic_ id: their picture
voicestring可选- a person's voice, one sentence: gender and age, pitch, timbre, pace, accent; written into every line of theirs
remove_from_bibleRemove a person or place from the series bible, in the draft.
workflowstring- a wf_ id
namestring- their name
make_pictureMake pictures into the library, 1 to 3 cents each, in seconds. With references it edits or combines them. Within the creator's daily limit it starts at once, above it the creator gets a Go card and this answers with a call id for wait. Never a picture that looks like a real person.
workflowstring- a wf_ id
wordsstring可选- what the picture model reads: for a new picture one English paragraph of 100-200 words, everyone an adult by decade; get_guide pictures says how
referencesstring可选- pic_ ids to edit or combine, in the order the words name them
ratiostring可选- its frame (9:16, 16:9)
resolutionstring可选- 720P unless asked (480P, 720P)
countinteger可选- how many, 1-4, each its own seed and price
for_biblestring可选- a bible name: the picture becomes theirs
redostring可选- the pic_ id of one that missed the ask: the new one takes its place in the draft; twice at most
fixstring可选- with redo: what was wrong with it
compose_musicMake music into the library from words: a song with its lyrics or an instrumental, about 7 cents a minute. Within the daily limit, else a Go card.
workflowstring- a wf_ id
descriptionstring- its caption; get_guide music says how
secondsinteger- the most it runs, 10-180
vocalsstring可选- (instrumental, sung)
lyricsstring可选- the sung words in sections, a lowercase tag on its own line
countinteger可选- how many, 1-4
lay_under_videoboolean可选- lay it under the whole video, in the draft
design_soundMake a sound effect or ambience into the library, or an instrumental from a library clip, about a cent. Within the daily limit, else a Go card.
workflowstring- a wf_ id
descriptionstring- the sound; get_guide music says how
secondsinteger- 10-60
clipstring可选- an aud_ id to make it from
clip_usestring可选- remix keeps its melody and timing; style makes a new piece with its sound (remix, style)
countinteger可选- how many, 1-4
lay_atnumber可选- where on the video's clock to lay it, in seconds, in the draft
lay_trackLay a library audio clip on the Sound lane under the video, in the draft, or move it or change its level or fades.
workflowstring- a wf_ id
clipstring- an aud_ id
startnumber可选- seconds
endnumber可选- seconds
volumenumber可选- 0-2; 1 = as made
fade_innumber可选- seconds: 0.1 (none), 0.5, 1, 2 or 4
fade_outnumber可选- seconds: 0.1 (none), 0.5, 1, 2 or 4
remove_trackTake a track off the Sound lane, in the draft.
workflowstring- a wf_ id
trackstring- T#, from open_workflow
set_formatChange the whole video's settings, in the draft. Pass only what changes.
workflowstring- a wf_ id
namestring可选- the workflow's name
speech_languagestring可选- the language its spoken lines are in (Arabic, Chinese, English, French, German, Italian, Japanese, Korean, Portuguese, Russian, Spanish)
orientationstring可选- (portrait, landscape)
resolutionstring可选- one open_workflow lists
lookRead a scene's whole words or a document's, or see pictures, or have our reviewer watch a take, a preview or a library video, one at a time: it says what it sees, answers your question and sends frames. A whole take or video is heard too.
workflowstring- a wf_ id
targetstring- 'S2' or a doc_ id; or pic_ ids with commas; or a take_ id, a preview like 'S2.1' or a vid_ id, with pic_ ids after it to compare; or one moment, 'take_ab12cd34@13'; or a script's scene as the crew planned it, 'scene 7' or 'scenes 3-5'
questionstring可选- with a video: one open question in English on how something in it looks (what, who, where, how many, what colour); never yes or no, never naming what people do to each other
framesinteger可选- with a question: how many frames that show its answer come back, 1-9
break_down_scriptThe one call for a whole script, however long. Our crew breaks it into scenes, makes a picture for everyone and everywhere new (a cent each, within the daily limit), plans every shot and writes every scene, straight onto the workflow, with no stop. Answers with a job id: wait follows it, then quote, shoot and propose.
workflowstring- a wf_ id
scriptstring可选- the script's doc_ id
directionstring可选- how the creator wants the whole film shot, in their words
againboolean可选- true: break it down again from the start, as new scenes after the last ones, which stay until you remove_segment them
plan_shotsHave our crew read scenes' shot plans back from their words. A scene needs one to render.
workflowstring- a wf_ id
scenesstring可选- like 'S3,S7-S9'; every scene that lacks one if left out
write_scenesHave our crew write scenes of a broken-down script again, six at a time. Answers with a job id.
workflowstring- a wf_ id
scenesstring可选- like 'S3,S7-S9'; every scene not written yet if left out
shootAdd a full render of the video, or of a range, to the draft. It starts when the creator presses Use, or with land if they allow it.
workflowstring- a wf_ id
firststring可选- first scene, S1 if left out
laststring可选- last scene, the last if left out
quoteThe exact price in credits of a take or a preview, or what it would be with what you pass. Nothing changes.
workflowstring- a wf_ id
segmentstring可选- a scene: S2 (its place now) or seg_ab12cd34; a take of the whole video if left out
laststring可选- a take of a range: its last scene
previewboolean可选- true: the scene's 480P preview instead of a take
resolutionstring可选- one open_workflow lists
secondsnumber可选- what if each were this long
modestring可选- what if each rendered from (omni_reference, first_last_frame)
picturesinteger可选- what if each carried this many pictures
clipsinteger可选- what if each carried this many clips
videosinteger可选- what if each carried this many videos
deliverSave a take into the library as an MP4, with the Sound lane mixed in, and get its link. Free.
workflowstring- a wf_ id
takestring可选- a take_ id; the newest if left out
report_brokenSend a render that came out badly broken to our team's test set, with the words and pictures it was made from, when the creator says it is. Free, and nothing here changes.
workflowstring- a wf_ id
segmentstring- a scene: S2 (its place now) or seg_ab12cd34
problemstring- what is wrong, in the creator's own words
videostring可选- a take_ or job_ id: the video they mean; the scene's newest if left out
pull_stillSave one frame of a take into the library as a picture. Free.
workflowstring- a wf_ id
takestring可选- a take_ id; the newest if left out
atstring可选- seconds into it, or 'end'; its first frame if left out
clip_videoCut a stretch of a library video or a take into the library, 60 s at most, or its sound alone as a clip. Free.
workflowstring- a wf_ id
videostring- a vid_ or take_ id
startstring可选- seconds or a clock (9:50.5); its first second if left out
endstring可选- the same; its last second if left out
audioboolean可选- true: its sound alone
save_documentSave words as a document in the library. For a file on disk use upload_file: it costs you no tokens.
workflowstring- a wf_ id
namestring- its title
textstring- its words, whole
edit_footageEdit a saved take on the Edit lane, in the draft, with no new render: cut a stretch out, or play a library video in it, or with start = end put a video in whole, or put a stretch back. Free: build_edit then makes a new take of it, the take kept as it is.
workflowstring- a wf_ id
takestring可选- a take_ id; the newest if left out
startnumber- seconds into the take
endnumber- seconds into the take; = start to put a video in there
videostring可选- a vid_ id
own_soundboolean可选- with video over a stretch: keep the take's own sound under it
backboolean可选- true: put the stretch back as it was
color_gradeColour a saved take on the Edit lane, in the draft: a named look, then each number moves one slider. Free: build_edit makes a new take with it.
workflowstring- a wf_ id
takestring可选- a take_ id; the newest if left out
lookstring可选- original takes the look off (original, warm, cool, vivid, film, mono, vintage, night, airy)
exposureinteger可选- -100 to 100
contrastinteger可选- -100 to 100
saturationinteger可选- -100 to 100
temperatureinteger可选- -100 (blue) to 100 (orange)
tintinteger可选- -100 (green) to 100 (magenta)
fadeinteger可选- 0-100: lifted, matte blacks
subtitleCaptions on a saved take from what is said in it, in the draft: on, off, their style, or one line's words fixed. Free: build_edit burns them in.
workflowstring- a wf_ id
takestring可选- a take_ id; the newest if left out
onboolean可选- true: make them; false: take them off
stylestring可选- (clean, bold, boxed)
fontstring可选- (noto-sans-sc, noto-serif-sc, lxgw-wenkai, smiley-sans, zcool-kuaile, zcool-qingke-huangyou, zcool-xiaowei, ma-shan-zheng, zhi-mang-xing, inter, montserrat, bebas-neue, oswald, anton, playfair-display, eb-garamond)
linestring可选- C#, from open_workflow: the line to fix
textstring可选- with line: its words as said
set_transitionA dip to black or white or a dissolve on a saved take, where its picture changes, in the draft. Free: build_edit makes it.
workflowstring- a wf_ id
takestring可选- a take_ id; the newest if left out
kindstring- a dissolve needs a shot either side (black, white, dissolve, none)
scenestring可选- the scene change into this scene
all_scenesboolean可选- true: every scene change
atnumber可选- seconds into the take: 0, its end or a mark's edge
secondsnumber可选- 0.3 quick, 0.6 (unless asked), 1 slow
set_production_soundThe video's own sound on the Sound lane, in the draft: its level, or a stretch silent, or heard again.
workflowstring- a wf_ id
volumenumber可选- 0-1; 1 = as rendered
silent_startnumber可选- seconds on the video's clock
silent_endnumber可选- seconds on the video's clock; 0.3 s at least
backboolean可选- true: those silent stretches are heard again
waitFollow what is under way: call and job ids, or everything on a workflow, including a Go card and the creator's answer to propose. It answers when one ends, or after up_to seconds, with how long is left: with a shell, sleep that long first, so that waiting costs no tokens.
idsstring可选- call_ and job_ ids with commas
workflowstring可选- a wf_ id: everything under way on it
up_tointeger可选- seconds to hold, 50 if left out, 90 at most