一个 REST API 密钥即可调用 LLM、图像、音频、虚拟形象和视频。语音 TTS 首个音频字节约 100ms,图像数秒,视频通过异步任务返回。
| 端点 | 方式 | 速度 |
|---|---|---|
音频 /audio/speech | 同步 | 首个音频 ~85–120ms / 短文本整体不到 1 秒 |
图像 /images/generations | 同步 | ~4 秒(1024²,20 steps) |
视频 /videos/generations | 异步任务 | ~60–90 秒(轮询任务 id) |
每个请求都需将 API 密钥作为 Bearer 令牌发送。可在“API 管理”页面签发密钥(明文仅在创建时显示一次)。
Authorization: Bearer kotonia_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
兼容 OpenAI 的 chat completions 端点。只需把 OpenAI 的 Python / JS SDK 的 base_url 指向我们即可直接使用。tools / tool_choice 原样透传,因此 agent 场景也能用原生 tool calling。
curl -X POST https://kotonia.ai/api/v1/chat/completions \
-H "Authorization: Bearer $KOTONIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kotonia-llm-basic",
"messages": [ { "role": "user", "content": "Hello!" } ]
}'
# → OpenAI-shaped: { "choices": [ { "message": { "content": "..." } } ],
# "usage": { ... }, "timing": { "total_ms": 480 } }from openai import OpenAI
client = OpenAI(
base_url="https://kotonia.ai/api/v1",
api_key="YOUR_KOTONIA_API_KEY", # kotonia_...
)
resp = client.chat.completions.create(
model="kotonia-llm-basic", # free (local) · or "kotonia-llm-standard" (metered)
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://kotonia.ai/api/v1",
apiKey: process.env.KOTONIA_API_KEY, // kotonia_...
});
const resp = await client.chat.completions.create({
model: "kotonia-llm-basic",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(resp.choices[0].message.content);提供两个模型:
注: 目前不支持 stream:true(内部回退为非流式)。max_tokens 有上限。可通过响应中的 timing 查看速度。
还提供兼容 Anthropic Messages API 的 /messages 端点。把官方 Anthropic SDK 或 Claude Code 的 base_url 指向我们即可(同一个 kotonia_ 密钥作为 x-api-key 发送)。tools / tool_result 会在内部与 OpenAI 形式互相转换并透传。
curl -X POST https://kotonia.ai/api/v1/messages \
-H "x-api-key: $KOTONIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kotonia-llm-basic",
"max_tokens": 256,
"messages": [ { "role": "user", "content": "Hello!" } ]
}'
# → { "type": "message", "content": [ { "type": "text", "text": "..." } ],
# "stop_reason": "end_turn", "usage": { "input_tokens": N, "output_tokens": M } }from anthropic import Anthropic
client = Anthropic(
base_url="https://kotonia.ai/api", # the SDK appends /v1/messages
api_key="YOUR_KOTONIA_API_KEY", # kotonia_... (sent as x-api-key)
)
msg = client.messages.create(
model="kotonia-llm-basic", # or "kotonia-llm-standard" (metered)
max_tokens=256,
messages=[{"role": "user", "content": "Hello!"}],
)
print(msg.content[0].text)注: SDK 会在末尾追加 /v1/messages,因此 base_url 应设为 /api(而非 /api/v1)。暂不支持流式,图像块不转换(以文本/工具为主)。
curl https://kotonia.ai/api/v1/images/loras \
-H "Authorization: Bearer $KOTONIA_API_KEY"
# → { "model": "hidream-o1-image", "loras": [ { "name": "kotonia03", "requires_paid": false } ] }
# Use a returned name in /images/generations:
# "loras": [ { "name": "kotonia03", "weight": 0.75 } ]curl -X POST https://kotonia.ai/api/v1/images/generations \
-H "Authorization: Bearer $KOTONIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "a serene japanese garden at dawn, soft light",
"size": "1024x1024",
"steps": 20
}'
# → { "data": [ { "b64_json": "<PNG base64>" } ], "timing": { "total_ms": 4200 } }可选: seed, guidance_scale, shift, ref_image(base64,编辑模式)、loras([{name, weight}],支持叠加)。GET /images/loras 返回已加载的 name 和 requires_paid(image 作用域)。weight 为 0〜2,默认 1。也支持 lora / lora_weight 单个指定,loras 优先。参考图像编辑也可使用。限制: prompt 不超过 4000 字、size 每边 256〜2048(超出返回 400)。
curl "https://kotonia.ai/api/v1/audio/voices?engine=voxcpm" \
-H "Authorization: Bearer $KOTONIA_API_KEY"
# → { "engine": "voxcpm", "voices": [
# { "ref_id": "...", "label": "...", "description": "...", "native_lang": "en",
# "visibility": "official", "mine": false }
# ] }
# Use the same engine and a returned ref_id in /audio/speech or /audio/generations:
# "engine": "voxcpm", "ref_id": "<ref_id from list>"
# For Irodori references, list with ?engine=irodori instead.curl -X POST https://kotonia.ai/api/v1/audio/speech \
-H "Authorization: Bearer $KOTONIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "Hello, what a lovely day.",
"engine": "voxcpm",
"language": "en"
}' \
--output speech.frames
# Binary stream: repeated [4-byte big-endian WAV length][WAV bytes]engine: voxcpm(默认、多语言)/ irodori / voicevox。可选: voice, speed, instruct, ref_id, seed。voxcpm 中 voice 为声音设计描述。GET /audio/voices?engine=voxcpm(或 irodori)返回官方、公开及自己的参考声音(audio 作用域,默认 voxcpm)。使用相同 engine 和返回的 ref_id,可在流式及批处理合成中固定声音。此列表不包含 VOICEVOX 说话人。限制: input 不超过 4000 字。流中为带长度前缀的 WAV 帧。
curl -X POST https://kotonia.ai/api/v1/audio/generations \
-H "Authorization: Bearer $KOTONIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "Hello, what a lovely day.",
"engine": "voxcpm",
"language": "en"
}'
# → { "audio": { "b64": "<WAV base64>", "format": "wav", "sample_rate": 48000 },
# "timing": { "first_byte_ms": 60, "total_ms": 480 } }curl -X POST https://kotonia.ai/api/v1/audio/transcriptions \
-H "Authorization: Bearer $KOTONIA_API_KEY" \
-F "file=@speech.wav"
# → { "text": "...", "timing": { "stt_api_ms": 320, "total_server_ms": 325 } }以 multipart/form-data 的 file 字段发送文件。上传上限为 25MB。
# List prepared avatars
curl https://kotonia.ai/api/v1/avatars \
-H "Authorization: Bearer $KOTONIA_API_KEY"
# Stream speech plus avatar frames
curl -X POST https://kotonia.ai/api/v1/avatars/my-avatar/speech \
-H "Authorization: Bearer $KOTONIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "input": "Hello!", "tts_backend": "voxcpm", "language": "en", "fps": 25 }' \
--output avatar.stream
# Binary stream: repeated [1-byte type][4-byte big-endian length][payload]
# type 0 = WAV audio, type 1 = JPEG video frameGET /avatars 与发言需要 avatar 作用域;POST/DELETE 需要管理员签发的 avatar:write 作用域。发言流中 type 0 为 WAV 音频,type 1 为 JPEG 帧。
# 1) submit job
curl -X POST https://kotonia.ai/api/v1/videos/generations \
-H "Authorization: Bearer $KOTONIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "prompt": "a cat walking through neon-lit streets", "width": 768, "height": 512 }'
# → { "id": "<job_id>", "status": "queued", "poll_url": "/api/v1/videos/generations/<job_id>" }
# 2) poll
curl https://kotonia.ai/api/v1/videos/generations/<job_id> \
-H "Authorization: Bearer $KOTONIA_API_KEY"
# → { "status": "completed", "data": [ { "url": "/api/ltx/video?path=..." } ] }可选: image(base64,I2V)、audio(base64,A2V 口型同步)、num_frames。限制: prompt 不超过 4000 字、width/height 每边 256〜1280、num_frames 不超过 200(超出返回 400)。
200 | 成功。图像/音频返回 body(base64),视频返回任务 id。 |
400 | 请求错误。缺少或非法参数(如缺少 prompt / input、base64 错误)。 |
401 | 认证错误。API 密钥缺失或无效(检查 Authorization 头)。 |
429 | 超出限制(Too Many Requests)。超过免费额度的每日上限。JST 午夜重置。 |
503 | 服务不可用。生成服务暂时不可用/繁忙,请稍后重试。 |