宇宙生成

宇宙生成 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.
query string 可选
words in the name
create_workflowA new workflow. It joins the ones you can see. Free.
name string
its name
orientation string 可选
landscape unless asked (portrait, landscape)
resolution string 可选
720P unless asked (480P, 720P)
speech_language string 可选
the language its spoken lines are in
like string 可选
a wf_ id: its settings, and with cast its people and places, come along
cast string 可选
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.
workflow string
a wf_ id
name string 可选
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.
query string 可选
words in its name or prompt
kind string 可选
(picture, audio, video, document, bible)
workflow string 可选
a wf_ id: only there
made_by string 可选
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.
name string
the file's name, with its extension
type string
its content type, e.g. text/markdown, image/png
size integer
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.
topic string 可选
(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.
workflow string
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.
workflow string
a wf_ id
segment string
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.
workflow string
a wf_ id
segment string
a scene: S2 (its place now) or seg_ab12cd34
words string
the exact text the video model reads
shots string 可选
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.
workflow string
a wf_ id
frm string
a wf_ id: the workflow they are in
names string
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).
workflow string
a wf_ id
url string 可选
the url upload_file gave
name string
what to call it, with its extension
content_base64 string 可选
the file's bytes
type string 可选
with content_base64: its content type
copy_resourcesPut library items of other workflows into this one's library: the same files, new rows.
workflow string
a wf_ id
ids string
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.
workflow string
a wf_ id
id string
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.
workflow string
a wf_ id
sayPut a line in the dock for the creator to read in Studio: what you are doing, or what you need.
workflow string
a wf_ id
text string
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.
workflow string
a wf_ id
message string 可选
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.
workflow string
a wf_ id
add_segmentsAdd empty scenes to the draft. Give them words with write_segment: our cinematographer writes them.
workflow string
a wf_ id
count integer
how many, 1-20
after string 可选
the scene to add them after; S0 puts them first; left out: at the end
seconds integer 可选
each one's length, 5-15
mode string 可选
what they render from (omni_reference, first_last_frame)
continues boolean 可选
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.
workflow string
a wf_ id
segment string
a scene: S2 (its place now) or seg_ab12cd34
seconds integer 可选
5-15
mode string 可选
(omni_reference, first_last_frame)
continues boolean 可选
true: no cut from the scene before
move_to integer 可选
new position, 1 = first
remove_segmentRemove a scene from the draft. The ones after it move up.
workflow string
a wf_ id
segment string
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.
workflow string
a wf_ id
brief string
what the creator asks, word for word
seconds integer 可选
how long the whole video is, in seconds
episodes integer 可选
how many episodes
script string 可选
a doc_ id: the script to change; left out, a new story
pitch boolean 可选
true: two loglines to choose from, nothing saved
script_only boolean 可选
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.
workflow string
a wf_ id
segment string
a scene: S2 (its place now) or seg_ab12cd34
note string
what it shows, in the creator's words: every fact, act, line, camera note and timing; for a change, only what changes
shots string 可选
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).
workflow string
a wf_ id
segment string
a scene: S2 (its place now) or seg_ab12cd34
cast string 可选
who is in it, by bible name in the order its words number them, e.g. '@Mia, @Kitchen'; 'none' clears them
pictures string 可选
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
mute string 可选
vid_ ids among them whose own sound is off; '' turns all sound on
first string 可选
a pic_ id, or 'none'
last string 可选
a pic_ id, or 'none'
add_to_bibleAdd a person or place to the series bible in the draft, or change one, by name.
workflow string
a wf_ id
kind string
(person, place)
name string
their name
look string 可选
one sentence in the creator's language: a person's age (an adult), hair, face, build, clothes; a place's look and light
pronoun string 可选
(she, he)
picture string 可选
a pic_ id: their picture
voice string 可选
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.
workflow string
a wf_ id
name string
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.
workflow string
a wf_ id
words string 可选
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
references string 可选
pic_ ids to edit or combine, in the order the words name them
ratio string 可选
its frame (9:16, 16:9)
resolution string 可选
720P unless asked (480P, 720P)
count integer 可选
how many, 1-4, each its own seed and price
for_bible string 可选
a bible name: the picture becomes theirs
redo string 可选
the pic_ id of one that missed the ask: the new one takes its place in the draft; twice at most
fix string 可选
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.
workflow string
a wf_ id
description string
its caption; get_guide music says how
seconds integer
the most it runs, 10-180
vocals string 可选
(instrumental, sung)
lyrics string 可选
the sung words in sections, a lowercase tag on its own line
count integer 可选
how many, 1-4
lay_under_video boolean 可选
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.
workflow string
a wf_ id
description string
the sound; get_guide music says how
seconds integer
10-60
clip string 可选
an aud_ id to make it from
clip_use string 可选
remix keeps its melody and timing; style makes a new piece with its sound (remix, style)
count integer 可选
how many, 1-4
lay_at number 可选
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.
workflow string
a wf_ id
clip string
an aud_ id
start number 可选
seconds
end number 可选
seconds
volume number 可选
0-2; 1 = as made
fade_in number 可选
seconds: 0.1 (none), 0.5, 1, 2 or 4
fade_out number 可选
seconds: 0.1 (none), 0.5, 1, 2 or 4
remove_trackTake a track off the Sound lane, in the draft.
workflow string
a wf_ id
track string
T#, from open_workflow
set_formatChange the whole video's settings, in the draft. Pass only what changes.
workflow string
a wf_ id
name string 可选
the workflow's name
speech_language string 可选
the language its spoken lines are in (Arabic, Chinese, English, French, German, Italian, Japanese, Korean, Portuguese, Russian, Spanish)
orientation string 可选
(portrait, landscape)
resolution string 可选
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.
workflow string
a wf_ id
target string
'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'
question string 可选
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
frames integer 可选
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.
workflow string
a wf_ id
script string 可选
the script's doc_ id
direction string 可选
how the creator wants the whole film shot, in their words
again boolean 可选
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.
workflow string
a wf_ id
scenes string 可选
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.
workflow string
a wf_ id
scenes string 可选
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.
workflow string
a wf_ id
first string 可选
first scene, S1 if left out
last string 可选
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.
workflow string
a wf_ id
segment string 可选
a scene: S2 (its place now) or seg_ab12cd34; a take of the whole video if left out
last string 可选
a take of a range: its last scene
preview boolean 可选
true: the scene's 480P preview instead of a take
resolution string 可选
one open_workflow lists
seconds number 可选
what if each were this long
mode string 可选
what if each rendered from (omni_reference, first_last_frame)
pictures integer 可选
what if each carried this many pictures
clips integer 可选
what if each carried this many clips
videos integer 可选
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.
workflow string
a wf_ id
take string 可选
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.
workflow string
a wf_ id
segment string
a scene: S2 (its place now) or seg_ab12cd34
problem string
what is wrong, in the creator's own words
video string 可选
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.
workflow string
a wf_ id
take string 可选
a take_ id; the newest if left out
at string 可选
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.
workflow string
a wf_ id
video string
a vid_ or take_ id
start string 可选
seconds or a clock (9:50.5); its first second if left out
end string 可选
the same; its last second if left out
audio boolean 可选
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.
workflow string
a wf_ id
name string
its title
text string
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.
workflow string
a wf_ id
take string 可选
a take_ id; the newest if left out
start number
seconds into the take
end number
seconds into the take; = start to put a video in there
video string 可选
a vid_ id
own_sound boolean 可选
with video over a stretch: keep the take's own sound under it
back boolean 可选
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.
workflow string
a wf_ id
take string 可选
a take_ id; the newest if left out
look string 可选
original takes the look off (original, warm, cool, vivid, film, mono, vintage, night, airy)
exposure integer 可选
-100 to 100
contrast integer 可选
-100 to 100
saturation integer 可选
-100 to 100
temperature integer 可选
-100 (blue) to 100 (orange)
tint integer 可选
-100 (green) to 100 (magenta)
fade integer 可选
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.
workflow string
a wf_ id
take string 可选
a take_ id; the newest if left out
on boolean 可选
true: make them; false: take them off
style string 可选
(clean, bold, boxed)
font string 可选
(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)
line string 可选
C#, from open_workflow: the line to fix
text string 可选
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.
workflow string
a wf_ id
take string 可选
a take_ id; the newest if left out
kind string
a dissolve needs a shot either side (black, white, dissolve, none)
scene string 可选
the scene change into this scene
all_scenes boolean 可选
true: every scene change
at number 可选
seconds into the take: 0, its end or a mark's edge
seconds number 可选
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.
workflow string
a wf_ id
volume number 可选
0-1; 1 = as rendered
silent_start number 可选
seconds on the video's clock
silent_end number 可选
seconds on the video's clock; 0.3 s at least
back boolean 可选
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.
ids string 可选
call_ and job_ ids with commas
workflow string 可选
a wf_ id: everything under way on it
up_to integer 可选
seconds to hold, 50 if left out, 90 at most