開發者檔案

接入前先了解 API 契約。

為希望快速從想法進入產品整合的團隊提供專注、清晰的 API。實際可用性始終由即時模型目錄控制。

萬鑰支援的 OpenAI-compatible 子集

萬鑰提供由即時模型目錄控制的 OpenAI-compatible 介面,涵蓋文字(Chat Completions 與 Responses)、圖像生成與編輯、影片、語音合成與辨識、向量、視覺分析與聯網搜尋。它不是完整或現行的官方 OpenAI API 映象;只有通過萬鑰模型、計價、憑證與發佈門禁的模型,才會出現在 /v1/models 並接受請求。

發送請求前請先呼叫 /v1/models 或查看首頁價目表,確認要呼叫的模型 ID 與即時定價。所有價格直接讀自計費系統,調價當天生效。

如果由 SDK 或 Agent 自動接入,請讀取 /v1/openapi.json。它是公開端點、請求欄位、multipart 表單、響應與錯誤格式的唯一機器可讀來源;Provider 名稱與上游模型名稱屬於內部資訊,客戶端不需要傳送。

1. 快速開始

先呼叫 /v1/models 確認目前已上架的模型 ID,再在主控台建立正式 API Key(請儲存在服務端環境變數中),並將 baseURL 指到 https://api.star1age.cn/v1。生成類非文字端點均要求攜帶 Idempotency-Key。

curl https://api.star1age.cn/v1/models \
  -H "Authorization: Bearer $STAR1AGE_API_KEY"

OpenAI JavaScript SDK

OpenAI JavaScript 客戶端透過自訂 baseURL 即可呼叫萬鑰文字與生圖介面。請將 API Key 儲存在服務端環境變數中;生圖端點回傳 202 與 status_url,須攜帶 Idempotency-Key 並輪詢 /v1/requests/:id 取得結果;影片建立請使用下方說明的 multipart/form-data 任務契約。

npm install openai

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.STAR1AGE_API_KEY,
  baseURL: 'https://api.star1age.cn/v1'
});

const chat = await client.chat.completions.create({
  model: 'star1age-gpt-6.2-sol',
  messages: [{role: 'user', content: 'Hello'}]
});
console.log(chat.choices[0]?.message?.content);

const image = await client.images.generate(
  {
    model: 'star1age-gpt-image-2',
    prompt: 'A cinematic city at dusk',
    size: '1024x1024',
    n: 1,
    response_format: 'url'
  },
  {headers: {'Idempotency-Key': 'image-demo-001'}}
);
console.log(image);

OpenAI Python SDK

OpenAI Python 客戶端使用 base_url 即可呼叫萬鑰文字與生圖介面。請勿把 Key 提交到原始碼管理;生圖端點回傳 202 與 status_url,須透過 extra_headers 傳入 Idempotency-Key 並輪詢 /v1/requests/:id;影片建立請使用下方「影片」章節的 multipart/form-data 任務契約。

pip install openai

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["STAR1AGE_API_KEY"],
    base_url="https://api.star1age.cn/v1",
)

chat = client.chat.completions.create(
    model="star1age-gpt-6.2-sol",
    messages=[{"role": "user", "content": "Hello"}],
)
print(chat.choices[0].message.content)

image = client.images.generate(
    model="star1age-gpt-image-2",
    prompt="A cinematic city at dusk",
    size="1024x1024",
    n=1,
    response_format="url",
    extra_headers={"Idempotency-Key": "image-demo-001"},
)
print(image)

2. 驗證與許可權

生產環境使用 Authorization: Bearer sa_live_... 傳送 Key。Key 只會在建立或輪換成功時完整顯示一次。請只授予應用所需許可權;缺少對應許可權時,服務端會拒絕請求。某個許可權可以先於對應模型存在;實際可用模型始終以 /v1/models 為準。

Authorization: Bearer sa_live_...

Available scopes:
  models:read
  chat:generate
  responses:generate
  images:generate
  images:edit
  videos:generate
  videos:read
  audio:speech
  audio:transcribe
  web:search
  embeddings:create
  vision:analyze

3. 圖像

POST /v1/images/generations 與 POST /v1/images/edits 均建立持久化非同步任務,立即回傳 HTTP 202 與 status_url,請輪詢 GET /v1/requests/:id 取得受控簽名資產 URL。生圖支援 model、prompt、size、quality、n、response_format、negative_prompt、seed、watermark、prompt_extend、enable_interleave 及可選 parameters 物件(像 1280*720 這樣的尺寸會原樣傳遞);修圖使用 multipart/form-data 上傳原圖或傳入自有 Asset ID,不接受外部圖片 URL。完整 schema 請讀取 /v1/openapi.json。

# Generate an image (returns 202 with status_url; poll /v1/requests/:id)
curl https://api.star1age.cn/v1/images/generations \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: image-demo-001" \
  -d '{
    "model": "star1age-wan2.7-image-pro",
    "prompt": "A cinematic city at dusk",
    "size": "1280*720",
    "n": 1,
    "watermark": false,
    "response_format": "url"
  }'

# Edit an image (multipart upload or owned asset IDs; external URLs are not accepted)
curl https://api.star1age.cn/v1/images/edits \
  -X POST \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Idempotency-Key: image-edit-demo-001" \
  -F "model=star1age-qwen-image-edit" \
  -F "prompt=Replace the background with a clear dusk sky" \
  -F "image=@input.png"

# Poll durable request status until succeeded
curl https://api.star1age.cn/v1/requests/req_id \
  -H "Authorization: Bearer $STAR1AGE_API_KEY"

4. 影片

萬鑰在 POST /v1/videos 提供非同步 multipart/form-data 影片任務介面,並要求攜帶 Idempotency-Key。建立後使用回傳的 video id 呼叫 GET /v1/videos/:id 輪詢(或 GET /v1/videos/:id/events 訂閱進度),直到狀態為 completed,再透過 /content 取得成片。模型 ID、解析度、畫幅、時長、原生參數、可接受的參考素材與目前價格均以公開模型目錄為準。HappyHorse 1.0 對外提供完整的 720P/1080P、3~15 秒、九種畫幅、watermark 與 seed contract。影片列表支援 after、limit 與 order 游標參數。

curl https://api.star1age.cn/v1/videos \
  -X POST \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Idempotency-Key: video-demo-001" \
  -F "model=star1age-happyhorse-1.0" \
  -F "prompt=A slow aerial shot over a neon-lit city at night." \
  -F "seconds=5" \
  -F "size=1280x720"

curl https://api.star1age.cn/v1/videos/video_request_id \
  -H "Authorization: Bearer $STAR1AGE_API_KEY"

curl -L https://api.star1age.cn/v1/videos/video_request_id/content \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -o output.mp4

5. 語音、向量、視覺與聯網搜尋

萬鑰同時提供語音合成(POST /v1/audio/speech)、語音辨識(POST /v1/audio/transcriptions)、自訂音色管理(/v1/audio/voices)、文字與多模態向量(POST /v1/embeddings)、獨立聯網搜尋(POST /v1/web-search)與圖像/影片視覺分析(POST /v1/vision/analyze)。上述端點均要求攜帶 Idempotency-Key;其中語音合成與語音辨識會立即回傳 HTTP 202 與 status_url,請輪詢 GET /v1/requests/:id 取得受控音訊或轉寫結果;視覺分析僅接受 multipart 上傳或自有 Asset ID,不接受外部 URL。

# Speech synthesis (returns 202; poll /v1/requests/:id)
curl https://api.star1age.cn/v1/audio/speech \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: speech-demo-001" \
  -d '{
    "model": "star1age-qwen-audio-3.0-tts-flash",
    "input": "Welcome to Wanyra.",
    "voice": "longanhuan_v3.6",
    "response_format": "wav"
  }'

# Audio transcription (returns 202; poll /v1/requests/:id)
curl https://api.star1age.cn/v1/audio/transcriptions \
  -X POST \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Idempotency-Key: asr-demo-001" \
  -F "model=star1age-paraformer-v2" \
  -F "file=@sample.wav"

# Embeddings
curl https://api.star1age.cn/v1/embeddings \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: emb-demo-001" \
  -d '{
    "model": "star1age-text-embedding-v4",
    "input": ["Hello Wanyra"]
  }'

# Web search
curl https://api.star1age.cn/v1/web-search \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: search-demo-001" \
  -d '{
    "model": "star1age-web-search",
    "queries": ["Wanyra OpenAI compatible API"]
  }'

# Vision analysis (multipart image/video upload or owned asset ID)
curl https://api.star1age.cn/v1/vision/analyze \
  -X POST \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Idempotency-Key: vision-demo-001" \
  -F "model=star1age-qwen3-vl-flash" \
  -F "input=Describe the main subject in one sentence." \
  -F "input_reference=@scene.jpg"

6. 錯誤處理

錯誤使用包含 message、type、param 與 code 的結構化物件。4xx 通常表示請求或許可權問題;5xx 可能表示 Provider 或臨時服務故障。請保留響應中的 x-request-id Header,便於排查與支援。

{
  "error": {
    "message": "Rate limit exceeded.",
    "type": "rate_limit_error",
    "param": null,
    "code": "rate_limit_exceeded"
  }
}

7. 速率限制

API 同時按 API Key 與 IP 維度限流。請讀取響應 Header,不要把重試間隔寫死。超過限制時返回 429,Retry-After 會提供服務端建議等待秒數。

x-ratelimit-limit-key: <current-key-limit>
x-ratelimit-remaining-key: <remaining-key-requests>
x-ratelimit-limit-ip: <current-ip-limit>
x-ratelimit-remaining-ip: <remaining-ip-requests>
retry-after: <seconds>

8. 冪等請求

Idempotency-Key 是萬鑰為生成類介面提供的冪等鍵:圖像、影片、語音、向量、視覺分析與聯網搜尋端點均強制要求傳入;文字介面(Chat Completions 與 Responses)可選傳入,用於斷線續傳或防重。同一 API Key、端點和 payload 在 24 小時內使用相同 Key 會複用原結果;相同 Key 搭配不同 payload 會回傳衝突,不會建立第二個任務。

Idempotency-Key: checkout-image-20261122-001

9. 文字串流

目錄中已啟用串流能力的文字模型,可在 POST /v1/chat/completions 與 POST /v1/responses 使用可續傳 SSE。重新連線時必須沿用同一個 Idempotency-Key,並將最後收到的 SSE id 放入 Last-Event-ID,服務端會從下一幀繼續;不傳 Last-Event-ID 則會從頭重播。客戶端關閉連線不會取消 Provider 執行:請求會在後臺繼續,完整加密結果會保留供重播,並照常依實際 usage 計費。

# Chat Completions SSE
curl -N https://api.star1age.cn/v1/chat/completions \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: chat-stream-demo-001" \
  -d '{
    "model": "star1age-gpt-6.2-sol",
    "messages": [{"role": "user", "content": "Reply with one short sentence."}],
    "stream": true,
    "stream_options": {"include_usage": true}
  }'

# Responses SSE
curl -N https://api.star1age.cn/v1/responses \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: responses-stream-demo-001" \
  -d '{
    "model": "star1age-gpt-6.2-sol",
    "instructions": "Be concise.",
    "input": "Reply with one short sentence.",
    "stream": true
  }'

# Resume after disconnect using the same request identity
curl -N https://api.star1age.cn/v1/chat/completions \
  -H "Authorization: Bearer $STAR1AGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: chat-stream-demo-001" \
  -H "Last-Event-ID: <last-sse-id>" \
  -d '{
    "model": "star1age-gpt-6.2-sol",
    "messages": [{"role": "user", "content": "Reply with one short sentence."}],
    "stream": true,
    "stream_options": {"include_usage": true}
  }'

10. API Reference

下方互動式 Reference 直接讀取 /v1/openapi.json,這是公開 API 契約的唯一來源。

正在載入 API Reference…
開發者檔案 | 萬鑰 Wanyra