OpenAI 相容 API 的建議 Base URL:
https://miyang.cn/v1 持續相容既有用戶端;新接請使用 https://miyang.cn/api/v1。
除公開的模型清單介面外,推論介面均須在請求標頭攜帶 API 金鑰。支援兩種請求標頭:
- 建議:
Authorization: Bearer miyang-xxxxx - 備用:
x-api-key: miyang-xxxxx
API 金鑰在主控台建立並加密保存,可在「API Keys」頁面再次檢視和複製。
# Bearer Token(推荐) curl https://miyang.cn/api/v1/models \ -H "Authorization: Bearer miyang-xxx" # x-api-key(备用) curl https://miyang.cn/api/v1/models \ -H "x-api-key: miyang-xxx"
模型 ID 通常採用 {provider_slug}/{model_name} 格式。建議使用 miyang/auto 自動選擇模型,也可透過模型清單介面或主控台複製其他可用的呼叫 ID。
miyang/auto— 自動選擇適合目前請求的模型miyang/standard— 標準檔模型miyang/premium— 進階檔模型
miyang/* 模型用於 Alice 用戶端;其他應用程式或指令碼請從模型清單中選擇 usage_scope 為 general 的模型。
# 自动选择适合当前请求的模型 model = "miyang/auto"
每個 API 金鑰獨立計數,預設 60 次/分鐘,可在主控台調整上限。超出限速返回 429 Too Many Requests。
{
"error": {
"message": "Rate limit exceeded",
"type": "rate_limit_error",
"code": 1002
}
}
結算單位為米粒,按呼叫即時扣費。目前儲值固定按 1 元人民幣 = 140 米粒 入帳,活動贈送另計。
- 呼叫前檢查餘額 > 0,餘額不足返回
402 - 按 prompt + completion token 用量計費
- 支援 Prompt Cache:
cache_read_tokens按折扣價計算
可在主控台儲值米粒,並在「用量明細」中檢視呼叫和消費紀錄。
// 余额不足响应(402) { "error": { "message": "Insufficient balance", "type": "insufficient_balance", "code": 1004 } }
OpenAI 相容的對話介面,支援串流與非串流輸出。可直接取代 OpenAI SDK 的 base_url。
| 參數 | 類型 | 說明 |
|---|---|---|
| model 必填 | string | 模型 ID,格式 provider_slug/model |
| messages 必填 | array | 對話訊息清單,每條含 role 和 content |
| stream | boolean | 是否啟用串流輸出(SSE),預設 false |
| temperature | float | 取樣溫度,範圍 0–2 |
| max_tokens | integer | 最大輸出 token 數 |
| response_format | object | 結構化輸出格式,見「結構化輸出」章節 |
curl https://miyang.cn/api/v1/chat/completions \ -H "Authorization: Bearer miyang-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "miyang/auto", "messages": [ {"role": "user", "content": "Hello!"} ], "stream": false }'
公開介面,無需 API 金鑰。返回目前公開可用模型;攜帶 API 金鑰時還會依帳號權限返回內部或白名單模型。回應欄位在標準 OpenAI 格式基礎上擴充了 pricing、context_length 和使用範圍資訊。
{
"object": "list",
"data": [
{
"id": "miyang/auto",
"object": "model",
"owned_by": "miyang",
"name": "自动",
"model_type": "text",
"usage_scope": "alice",
"usage_hint": "请在 Alice 客户端内使用",
"pricing": {
"prompt": "3.250000",
"completion": "13.500000",
"cache_read": "0.550000",
"cache_write": "0.000000"
},
"context_length": 262144
}
]
}
OpenAI 相容的向量介面。模型是否支援向量任務,請以模型清單和主控台標記為準。
| 參數 | 類型 | 說明 |
|---|---|---|
| model 必填 | string | Embedding 模型呼叫 ID |
| input 必填 | string / array | 需要向量化的文字或文字陣列 |
| encoding_format | string | 向量編碼格式,常用值為 float |
curl https://miyang.cn/api/v1/embeddings \ -H "Authorization: Bearer miyang-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "provider/embedding-model", "input": "需要向量化的文本" }'
miyang/jev-1.13 是提供給所有米羊 API 使用者的低成本結構化決策模型,底層固定為 typesafe/jev-1.13。它只回答明確問題,不生成對話文字;Alice 的長期記憶預篩是第一個正式用途。
Authorization: Bearer miyang-xxx 呼叫。它採用獨立 Decisions 協定,不相容 /api/v1/chat/completions,因此不會混入 Chat 專用的 /api/v1/models 清單。
| 模型資訊 | 值 |
|---|---|
| 米羊模型 ID | miyang/jev-1.13 |
| 決策引擎 | typesafe/jev-1.13 |
| 上下文上限 | 32768 tokens |
| 問題類型 | noul / choice / score |
| 價格 | 輸入 $0.042 / 1M tokens;輸出 $0.000 / 1M tokens。依上游回傳的實際 token 用量結算。 |
| 開放範圍 | 所有持有效米羊 API 金鑰的使用者 |
請求必須指定已登記的 Decisions 模型殼;Gateway 會依模型殼計費並固定真實上游。state 保存待判斷的結構化上下文,questions 定義要回答的問題。
| 參數 | 類型 | 說明 |
|---|---|---|
| model 必填 | string | 公開呼叫固定填寫 miyang/jev-1.13;內部場景模型殼不能由一般 API 使用者呼叫。 |
| state 必填 | object | 供決策使用的結構化狀態;呼叫方應在傳送前自行清理不必要的敏感資訊。 |
| questions 必填 | object | 以問題名稱為鍵的物件,至少 1 項,最多 24 項。 |
| questions.*.type 必填 | string | noul(0–1 機率)、choice(選項)或 score(分數)。 |
| questions.*.instructions 必填 | string | 清楚描述模型要判斷的問題。 |
| questions.*.criteria | object | 選填;說明各答案或分數分別代表什麼,以減少歧義。 |
單次請求內容最大 64 KiB,最多 24 個問題。伺服器不記錄 state 正文或決策答案,只記錄問題數量、耗時與 token 用量。
curl https://miyang.cn/api/v1/decisions \ -H "Authorization: Bearer miyang-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "miyang/jev-1.13", "state": {"dialog": "使用者詢問了一個一般技術問題"}, "questions": { "remember": { "type": "noul", "instructions": "這段對話是否包含值得長期保存的資訊?", "criteria": { "true": "包含穩定身分、長期偏好或明確關係事件", "false": "一次性任務、一般問答或寒暄" } } } }'
{
"model": "miyang/jev-1.13",
"provider": "miyang",
"answers": {
"remember": {
"type": "noul",
"noul": 0.02
}
}
}
OpenAI 相容的圖像生成介面。根據文字 prompt 生成圖像,回應返回圖片 URL 或 Base64 資料,與 OpenAI Images API 完全相容。
| 參數 | 類型 | 說明 |
|---|---|---|
| model 必填 | string | 模型 ID,格式 provider/model,如 ts/gpt-image-2 |
| prompt 必填 | string | 圖像描述文字 |
| n | integer | 生成圖像數量,預設 1,支援多張 |
| size | string | 圖像尺寸。常用值:1024x1024(方圖)、1024x1536(直圖)、1536x1024(橫圖)、auto(模型自動選擇)。最大邊長 3840px,兩邊須為 16 的倍數,長短邊比不超過 3:1 |
| quality | string | 算繪品質:low(快速草稿)、medium、high、auto(預設,模型自動選擇) |
| output_format | string | 輸出格式:png(預設)、jpeg(更快)、webp |
| output_compression | integer | 壓縮率 0–100,僅 JPEG / WebP 有效 |
| background | string | opaque(預設)或 transparent(透明背景,適合 icon/貼紙) |
| moderation | string | 內容審核:auto(預設)或 low(寬鬆) |
基礎範例 — 文生圖:
curl https://miyang.cn/api/v1/images/generations \ -H "Authorization: Bearer miyang-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "ts/gpt-image-2", "prompt": "A children'\''s book drawing of a veterinarian listening to the heartbeat of a baby otter", "size": "1024x1024", "quality": "high" }'
from openai import OpenAI import base64 client = OpenAI( api_key="miyang-xxx", base_url="https://miyang.cn/api/v1", timeout=180.0, # 图像生成需要较长超时 ) result = client.images.generate( model="ts/gpt-image-2", prompt="A children's book drawing of a veterinarian listening to the heartbeat of a baby otter", size="1024x1024", quality="high", ) print(result.data[0].url)
進階範例 — JPEG 輸出 + 壓縮 + 儲存到本機:
import httpx, json, base64 resp = httpx.post( "https://miyang.cn/api/v1/images/generations", headers={"Authorization": "Bearer miyang-xxx"}, json={ "model": "ts/gpt-image-2", "prompt": "A serene Japanese garden with a koi pond", "size": "1536x1024", "quality": "medium", "output_format": "jpeg", # jpeg 比 png 更快 "output_compression": 80, # 压缩率 0-100 }, timeout=180.0, ) data = resp.json() print(data["data"][0]["url"])
// 响应示例 { "created": 1779691963, "data": [ { "url": "https://image.token-recyclebin.com/images/2026/05/25/xxx.png", "revised_prompt": "A serene Japanese garden with a koi pond..." } ] }
尺寸與品質參考
| 參數 | 可選值 | 說明 |
|---|---|---|
| size | 1024x1024(方)1536x1024(橫)1024x1536(直)2048x2048(2K)3840x2160(4K 橫)auto | 最大邊長 ≤ 3840px,雙邊為 16 的倍數,比例 ≤ 3:1,總像素 655,360 – 8,294,400 |
| quality | low · medium · high · auto | low 最快,適合草稿和快速迭代;high 最精細,適合最終出圖 |
| output_format | png · jpeg · webp | jpeg 比 png 更快,優先用於對延遲敏感的情境 |
GPT Image 2 參考定價(米粒 / 張)
| Quality | 1024×1024 | 1024×1536 / 1536×1024 |
|---|---|---|
| Low | 6 米粒 | 5 米粒 |
| Medium | 53 米粒 | 41 米粒 |
| High | 211 米粒 | 165 米粒 |
OpenAI 相容的圖像編輯介面。上傳一張或多張參考圖,配合文字 prompt 生成新圖像。支援局部編輯(mask)和多圖合成。請求使用 multipart/form-data 格式。
典型情境:
- 風格轉換 — 上傳照片 + "轉為油畫風格"
- 多圖合成 — 上傳多張素材 + "生成包含這些物品的禮品籃"
- 局部編輯 — 上傳原圖 + mask + "在遮罩區域加入一隻紅鶴"
| 參數 | 類型 | 說明 |
|---|---|---|
| model 必填 | string | 模型 ID,如 ts/gpt-image-2 |
| image 必填 | file / file[] | 參考圖片。單張用 image,多張用 image[](支援多個 image[]=@file.png) |
| prompt 必填 | string | 編輯指令描述 |
| mask | file | 遮罩圖片(需含 alpha 通道),透明區域為需要編輯的部分。多圖時 mask 套用至第一張 |
| n | integer | 生成數量,預設 1 |
| size | string | 輸出尺寸,預設 auto,支援與 Generations 相同的尺寸選項 |
| quality | string | low · medium · high · auto |
單圖編輯 — 風格轉換:
curl https://miyang.cn/api/v1/images/edits \ -H "Authorization: Bearer miyang-xxx" \ -F "model=ts/gpt-image-2" \ -F "prompt=Turn this photo into a Studio Ghibli style illustration" \ -F "image=@photo.png" \ -F "size=1536x1024"
from openai import OpenAI client = OpenAI( api_key="miyang-xxx", base_url="https://miyang.cn/api/v1", timeout=180.0, ) result = client.images.edit( model="ts/gpt-image-2", image=open("photo.png", "rb"), prompt="Turn this photo into a Studio Ghibli style illustration", ) print(result.data[0].url)
多圖合成 — 將多張素材合成一張:
# 多图参考:用 image[] 传多张 curl https://miyang.cn/api/v1/images/edits \ -H "Authorization: Bearer miyang-xxx" \ -F "model=ts/gpt-image-2" \ -F "image[]=@lotion.png" \ -F "image[]=@soap.png" \ -F "image[]=@candle.png" \ -F 'prompt=A gift basket on a white background containing all these items'
局部編輯 — 使用 mask 遮罩:
# mask 需要有 alpha 通道,透明区域为编辑区 result = client.images.edit( model="ts/gpt-image-2", image=open("room.png", "rb"), mask=open("mask.png", "rb"), prompt="Add a flamingo in the pool area", quality="high", ) print(result.data[0].url)
非同步影片生成介面。建立成功後返回 task_id,請透過查詢介面輪詢任務狀態;不要用同一個業務請求重複建立任務。
miyang/h3 和 miyang/h3-max。
| 參數 | 類型 | 說明 |
|---|---|---|
| model 必填 | string | miyang/h3 或 miyang/h3-max |
| content 必填 | array | 多模態內容陣列,必須包含且只能包含一筆非空文字;可同時提供圖片、影片或音訊素材 |
| duration 必填 | integer | 輸出時長(秒)。H3 支援 4–15 秒;H3 Max 支援 5–15 秒 |
| resolution | string | 預設 768P。H3 支援 768P / 2K;H3 Max 支援 480P / 768P |
| ratio | string | 畫面比例:21:9、16:9、4:3、1:1、3:4、9:16;參考素材可用 adaptive |
| aigc_watermark | boolean | 是否加入 AIGC 浮水印 |
| extra | object | 僅 H3 Max 支援,可設定 prompt_expansion_mode:disabled、balanced 或 quality |
content 素材格式
| type | role | 說明 |
|---|---|---|
| text | — | 必填且只能一筆,最長 7000 字元 |
| image_url | first_frame / last_frame / reference_image | 首幀、尾幀或參考圖;單張未指定 role 時自動作為首幀 |
| video_url | reference_video | 參考影片,最多 3 個,必須指定 role |
| audio_url | reference_audio | 參考音訊,最多 3 個,必須指定 role |
curl https://miyang.cn/api/v1/videos/generations \ -H "Authorization: Bearer miyang-xxx" \ -H "Idempotency-Key: alice-video-001" \ -H "Content-Type: application/json" \ -d '{ "model": "miyang/h3", "content": [ {"type": "text", "text": "A lamb runs across a sunlit meadow"} ], "duration": 5, "resolution": "768P", "ratio": "16:9" }'
{
"task_id": "443429054845209"
}
使用者計費
下表為精確人民幣計價;實際扣費米粒按 CNY price ÷ CNY-per-USD rate × 1000 換算。
| 模型 | 計費項目 | 使用者價格 |
|---|---|---|
| miyang/h3 | 輸出影片 · 768P | ¥1.25 / s |
| miyang/h3 | 輸出影片 · 2K | ¥2.0 / s |
| miyang/h3 | 輸入參考影片 · 768P | ¥1.25 / s |
| miyang/h3 | 輸入參考影片 · 2K | ¥2.0 / s |
| miyang/h3 | 輸入參考圖(前 5 張免費,超出部分) | ¥0.5 / 張 |
| miyang/h3-max | 輸出影片 · 480P | ¥0.825 / s |
| miyang/h3-max | 輸出影片 · 768P | ¥1.25 / s |
| miyang/h3-max | 輸入參考影片 · 480P | ¥0.925 / s |
| miyang/h3-max | 輸入參考影片 · 768P | ¥2.425 / s |
| miyang/h3-max | 輸入參考圖(前 2 張免費,超出部分) | ¥1.25 / 張 |
| — | 輸入參考音訊 | 免費 |
使用建立任務返回的 task_id 輪詢。狀態可能為 queued、running、succeeded、failed 或 cancelled。建議每 5–15 秒查詢一次。
curl https://miyang.cn/api/v1/videos/generations/443429054845209 \
-H "Authorization: Bearer miyang-xxx"
{
"task": {
"status": "succeeded",
"resolution": "768P",
"duration": 5,
"content": {
"url": "https://signed.example/video.mp4",
"drive_file_id": "drv-xxx",
"size_bytes": 1757278,
"expires_in": 3600
}
}
}
取消仍在處理的任務並釋放計費預授權。若任務已有米羊盤檔案,取消時會一併移除;已完成且上游不允許取消時,以介面回應為準。
curl -X DELETE https://miyang.cn/api/v1/videos/generations/443429054845209 \
-H "Authorization: Bearer miyang-xxx"
為 Agent 和應用程式提供即時連網能力:網頁搜尋、新聞搜尋和網頁正文讀取。全部為 GET 介面,使用與推論介面相同的 API 金鑰鑑權(Authorization: Bearer miyang-xxx)。
| 介面 | 參數 | 說明 |
|---|---|---|
| /api/v1/websearch/search | q | 深度搜尋:結果附帶頁面正文擷取與重新排序上下文,適合 RAG |
| /api/v1/websearch/simple-search | q | 快速搜尋:僅返回標題和摘要,回應更快 |
| /api/v1/websearch/reader | url | 網頁讀取:擷取指定 URL 並轉成乾淨文字 |
| /api/v1/websearch/search-news | q | 新聞搜尋:只搜近期新聞源,結果同樣附帶檢索上下文 |
完整搜尋鏈路:搜尋 → 頁面內容擷取 → 向量檢索 → 重新排序。每條結果附帶 contexts 正文片段,可直接提供給模型做引用回答。回應時間通常 3–8 秒。
| 參數 | 類型 | 說明 |
|---|---|---|
| q 必填 | string | 搜尋關鍵字 |
curl "https://miyang.cn/api/v1/websearch/search?q=最新AI新闻" \ -H "Authorization: Bearer miyang-xxx"
// 响应示例 { "code": 200, "message": "ok", "took_ms": 4200, "data": { "organic": [ { "title": "AI News", "link": "https://example.com", "snippet": "Latest updates...", "contexts": [ { "idx": 0, "text": "..." } ] } ] } }
只做搜尋、不做頁面擷取和重新排序,通常 1 秒內返回。適合只需要標題 + 摘要 + 連結的情境。命中答案卡片時回應會額外包含 answerBox 欄位。
| 參數 | 類型 | 說明 |
|---|---|---|
| q 必填 | string | 搜尋關鍵字 |
curl "https://miyang.cn/api/v1/websearch/simple-search?q=最新AI新闻" \ -H "Authorization: Bearer miyang-xxx"
// 响应示例 { "code": 200, "message": "ok", "took_ms": 950, "data": { "answerBox": { "title": "Latest AI news", "snippet": "..." }, "organic": [ { "title": "AI News", "link": "https://example.com", "snippet": "Latest updates..." } ] } }
已知目標網頁 URL 時,擷取頁面並轉換為乾淨的 Markdown 文字。注意此介面返回的是頂層 content 欄位,而不是 data。
| 參數 | 類型 | 說明 |
|---|---|---|
| url 必填 | string | 要讀取的網頁位址,必須以 http:// 或 https:// 開頭 |
curl "https://miyang.cn/api/v1/websearch/reader?url=https://go.dev" \ -H "Authorization: Bearer miyang-xxx"
// 响应示例(content 为页面正文) { "code": 200, "message": "ok", "content": "# The Go Programming Language\n\nGo is an open source programming language..." }
只搜尋近期新聞源,其餘鏈路與深度搜尋一致,結果同樣附帶 contexts 正文片段。
404(回應體為 {"code": 404, "message": "no search results"}),這屬於正常業務結果,不扣費。
| 參數 | 類型 | 說明 |
|---|---|---|
| q 必填 | string | 新聞搜尋關鍵字 |
curl "https://miyang.cn/api/v1/websearch/search-news?q=OpenAI" \ -H "Authorization: Bearer miyang-xxx"
// 响应示例 { "code": 200, "message": "ok", "took_ms": 4200, "data": { "organic": [ { "title": "Latest OpenAI news", "link": "https://example.com/news", "snippet": "Recent product and research updates...", "contexts": [ { "idx": 0, "text": "..." } ] } ] } }
在請求體中設定 "stream": true 啟用串流輸出,回應格式與 OpenAI 的 SSE 規範完全相容。串流結束標記為 data: [DONE]。
from openai import OpenAI client = OpenAI( api_key="miyang-xxx", base_url="https://miyang.cn/api/v1", ) stream = client.chat.completions.create( model="miyang/auto", messages=[{"role": "user", "content": "Hello!"}], stream=True, ) for chunk in stream: print(chunk.choices[0].delta.content, end="")
透傳 response_format 欄位,支援 JSON Schema。由上游模型保證輸出格式,平台不做額外處理。
{
"model": "miyang/auto",
"messages": [...],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "result",
"schema": {
"type": "object",
"properties": {
"answer": { "type": "string" }
}
}
}
}
}
對支援 Prompt Cache 的模型,上游返回的快取命中 token 會按折扣價計費。平台完整透傳上游 usage 欄位,帳單中會顯示快取命中量。
不同供應商的欄位名稱有差異:
cache_read_input_tokens— Anthropicprompt_cache_hit_tokens— DeepSeekcached_tokens— OpenAI
{
"usage": {
"prompt_tokens": 1000,
"completion_tokens": 200,
"cache_read_input_tokens": 800, // Anthropic
"prompt_cache_hit_tokens": 800, // DeepSeek
"cached_tokens": 800 // OpenAI
}
}
只需取代 base_url 和 api_key,即可透過 OpenAI SDK 呼叫。
from openai import OpenAI client = OpenAI( api_key="miyang-xxx", base_url="https://miyang.cn/api/v1", ) resp = client.chat.completions.create( model="miyang/auto", messages=[{"role": "user", "content": "Hello!"}], ) print(resp.choices[0].message.content)
# 非流式 curl https://miyang.cn/api/v1/chat/completions \ -H "Authorization: Bearer miyang-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "miyang/auto", "messages": [{"role": "user", "content": "Hello"}] }' # 流式 curl https://miyang.cn/api/v1/chat/completions \ -H "Authorization: Bearer miyang-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "miyang/auto", "messages": [{"role": "user", "content": "Hello"}], "stream": true }'