专用模型POST
调用翻译、图片翻译、文档 OCR、音色复刻、音效与音乐生成、线稿生图等专用型号;请求体使用各厂商的原生字段。
POST https://api.tokentosea.com/v1/tools/invoke
专用型号各自有固定的输入结构,TokenToSea 不做协议转换:除 model 外,请求体按厂商原生字段书写。生成文件(图片、音频)会转存到私有存储,以签名链接返回。
前提:全能密钥或模型密钥,账户可用余额足以覆盖本次预留。Python 示例需要 pip install requests,Node.js 示例需要 Node.js 18+。
与工具 API 的区别
本接口调用的是模型(例如 glm-ocr),使用模型密钥,从 api.tokentosea.com 计费。调用 GitHub、npm 等外部数据工具请使用工具 API。
支持的型号#
截至 2026-10-21,以 GET /v1/models 为准。
| 型号 | 服务商 | 用途 | 返回方式 |
|---|---|---|---|
qwen-mt-uni | 千问 | 文本翻译 | 同步;"async": true 时异步 |
qwen-mt-image-2.0 | 千问 | 图片中的文字翻译 | 同步;"async": true 时异步 |
qwen-mt-image | 千问 | 图片中的文字翻译 | 异步 |
wan2.2-s2v-detect | 千问 | 检测图片是否适合音频驱动视频(wan2.2-s2v) | 同步 |
wanx-sketch-to-image-lite | 千问 | 线稿生图 | 异步 |
wanx-style-repaint-v1 | 千问 | 图片风格重绘 | 异步 |
wanx-x-painting | 千问 | 按蒙版局部重绘 | 异步 |
wanx-virtualmodel | 千问 | 虚拟模特 | 异步 |
glm-ocr | 智谱 | 文档版面与文字识别 | 同步 |
glm-tts-clone | 智谱 | 音色复刻并合成试听音频 | 同步 |
stepaudio-3-gen-preview | 阶跃星辰 | 音效生成 | 同步 |
stepaudio-3-music-preview | 阶跃星辰 | 音乐生成 | 异步 |
只支持 JSON 请求与非流式响应。
请求体#
| 型号 | 请求体 |
|---|---|
| 千问专用型号 | { "model", "input": { … }, "parameters": { … } },input 与 parameters 为厂商原生字段;provider_options.parameters 会合并进 parameters |
glm-ocr | { "model", "file": "<图片或文档 URL>" },其余字段原样转发智谱 |
glm-tts-clone | { "model", "file_id": "file_tts_…", "voice_name", "input" },file_id 为 /v1/files 上传的参考音频(purpose: "voice-clone-input") |
stepaudio-3-gen-preview | { "model", "task": "text_to_audio", "scripts": [{ "text": "…" }], "response_format": "mp3", "stream_format": "audio" } |
stepaudio-3-music-preview | { "model", "task": "text_to_music", "caption": "…", "instrumental": true, "response_format": "mp3" } |
各千问型号的验收示例:
| 型号 | input | parameters |
|---|---|---|
qwen-mt-uni | { "source_texts": "你好", "source_lang": "zh", "target_lang": "en" } | {} |
qwen-mt-image、qwen-mt-image-2.0 | { "image_url": "…", "source_lang": "zh", "target_lang": "en" } | {} |
wan2.2-s2v-detect | { "image_url": "…" } | {} |
wanx-sketch-to-image-lite | { "sketch_image_url": "…", "prompt": "一棵树" } | { "size": "768*768", "n": 1 } |
wanx-style-repaint-v1 | { "image_url": "…", "style_index": 3 } | { "n": 1 } |
wanx-x-painting | { "base_image_url": "…", "mask_image_url": "…", "prompt": "一个红色杯子" } | { "size": "1024*1024", "n": 1 } |
wanx-virtualmodel | { "base_image_url": "…", "mask_image_url": "…", "prompt": "…", "face_prompt": "…" } | { "short_side_size": "512", "n": 1 } |
完整的字段含义以千问文档、智谱文档、阶跃星辰文档为准。素材 URL 必须能被厂商公网访问。
响应#
- 同步、不生成文件的型号(
qwen-mt-uni、wan2.2-s2v-detect、glm-ocr):200,厂商原生响应体。 - 生成图片或音频的型号:完成后返回
{ "id", "model", "data": [{ "url", "asset_id", "mime_type" }], "usage"? },url最多 300 秒内有效,文件保留 30 天。 - 异步型号:
202与结果信封,用/v1/results/{key}轮询。 glm-tts-clone:响应中的voice被替换为平台音色 IDvoice_tts_…,file_id被替换为试听音频的file_tts_…。试听音频用GET /v1/files/{id}/content下载(WAV)。
示例#
文本翻译#
curl https://api.tokentosea.com/v1/tools/invoke \
-H "Authorization: Bearer $TOKENTOSEA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"model": "qwen-mt-uni",
"input": {"source_texts": "你好,世界", "source_lang": "zh", "target_lang": "en"},
"parameters": {}
}'import os
import uuid
import requests
response = requests.post(
"https://api.tokentosea.com/v1/tools/invoke",
headers={
"Authorization": "Bearer " + os.environ["TOKENTOSEA_API_KEY"],
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"model": "qwen-mt-uni",
"input": {"source_texts": "你好,世界", "source_lang": "zh", "target_lang": "en"},
"parameters": {},
},
timeout=120,
)
response.raise_for_status()
print(response.json()) # 厂商原生响应import { randomUUID } from 'node:crypto';
const response = await fetch('https://api.tokentosea.com/v1/tools/invoke', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.TOKENTOSEA_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': randomUUID(),
},
body: JSON.stringify({
model: 'qwen-mt-uni',
input: { source_texts: '你好,世界', source_lang: 'zh', target_lang: 'en' },
parameters: {},
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
console.log(await response.json()); // 厂商原生响应音色复刻(glm-tts-clone)#
先上传参考音频,再复刻音色并合成试听音频,最后下载试听文件。三步使用同一把密钥:平台资源与创建它的密钥绑定。
# 1. 上传参考音频,记下返回的 id(file_tts_…)
curl https://api.tokentosea.com/v1/files \
-H "Authorization: Bearer $TOKENTOSEA_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-F model=glm-tts-clone \
-F purpose=voice-clone-input \
-F "file=@reference.wav;type=audio/wav"
# 2. 复刻音色并合成试听音频
curl https://api.tokentosea.com/v1/tools/invoke \
-H "Authorization: Bearer $TOKENTOSEA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"model": "glm-tts-clone", "file_id": "file_tts_…", "voice_name": "我的音色", "input": "你好,欢迎使用语音服务。"}'
# 3. 下载试听音频(响应中的 file_id)
curl "https://api.tokentosea.com/v1/files/file_tts_…/content" \
-H "Authorization: Bearer $TOKENTOSEA_API_KEY" -o preview.wavimport os
import uuid
import requests
API = "https://api.tokentosea.com/v1"
HEADERS = {"Authorization": "Bearer " + os.environ["TOKENTOSEA_API_KEY"]}
with open("reference.wav", "rb") as audio:
uploaded = requests.post(
API + "/files",
headers={**HEADERS, "Idempotency-Key": str(uuid.uuid4())},
data={"model": "glm-tts-clone", "purpose": "voice-clone-input"},
files={"file": ("reference.wav", audio, "audio/wav")},
timeout=120,
)
uploaded.raise_for_status()
cloned = requests.post(
API + "/tools/invoke",
headers={**HEADERS, "Idempotency-Key": str(uuid.uuid4())},
json={"model": "glm-tts-clone", "file_id": uploaded.json()["id"], "voice_name": "我的音色", "input": "你好,欢迎使用语音服务。"},
timeout=300,
)
cloned.raise_for_status()
result = cloned.json()
print("voice:", result["voice"]) # voice_tts_…
preview = requests.get(API + "/files/" + result["file_id"] + "/content", headers=HEADERS, timeout=120)
preview.raise_for_status()
with open("preview.wav", "wb") as file:
file.write(preview.content)import { randomUUID } from 'node:crypto';
import { readFile, writeFile } from 'node:fs/promises';
const API = 'https://api.tokentosea.com/v1';
const headers = { Authorization: `Bearer ${process.env.TOKENTOSEA_API_KEY}` };
const form = new FormData();
form.set('model', 'glm-tts-clone');
form.set('purpose', 'voice-clone-input');
form.set('file', new Blob([await readFile('reference.wav')], { type: 'audio/wav' }), 'reference.wav');
const uploaded = await fetch(`${API}/files`, { method: 'POST', headers: { ...headers, 'Idempotency-Key': randomUUID() }, body: form });
if (!uploaded.ok) throw new Error(await uploaded.text());
const file = await uploaded.json();
const cloned = await fetch(`${API}/tools/invoke`, {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json', 'Idempotency-Key': randomUUID() },
body: JSON.stringify({ model: 'glm-tts-clone', file_id: file.id, voice_name: '我的音色', input: '你好,欢迎使用语音服务。' }),
});
if (!cloned.ok) throw new Error(await cloned.text());
const result = await cloned.json();
console.log('voice:', result.voice); // voice_tts_…
const preview = await fetch(`${API}/files/${result.file_id}/content`, { headers });
await writeFile('preview.wav', Buffer.from(await preview.arrayBuffer()));其他请求体#
{ "model": "glm-ocr", "file": "https://example.com/invoice.png" }{
"model": "stepaudio-3-gen-preview",
"task": "text_to_audio",
"scripts": [{ "text": "[一声清脆的铃声]" }],
"response_format": "mp3",
"stream_format": "audio"
}{
"model": "wanx-sketch-to-image-lite",
"input": { "sketch_image_url": "https://example.com/sketch.png", "prompt": "一棵树" },
"parameters": { "size": "768*768", "n": 1 }
}错误#
| 状态码 | code | 原因与处理 |
|---|---|---|
422 | async_operation_not_supported | wan2.2-s2v-detect 不支持 "async": true |
422 | use_owned_platform_resource | file_id 不是平台的 file_tts_… |
404 | resource_not_found | file_tts_… 不存在、已过期,或不是用当前密钥上传的 |
422 | audio_format_not_supported | 阶跃星辰型号的 response_format 不受支持 |
422 | endpoint_not_verified | 型号未开放本接口 |
4xx | provider_http_<状态码> | 厂商拒绝了请求,未扣费 |