产品文档

传统补全、DashScope 与账单兼容端点

更新于 2026-12-03

除核心对话接口外,Tengri 平台同步提供 Legacy Text Completions 续写接口、DashScope /compatible-mode/v1/* 兼容前缀,以及 OpenAI Billing 兼容余额与消费查询接口,便于存量应用与第三方客户端无缝迁移。语音合成与语音识别请分别接入平台专项能力 Heimori-TTS 与 语音识别。

一、传统文本续写(Legacy Completions):POST /v1/completions

用于兼容存量基于 prompt 字段调用的客户端;新业务推荐直接接入 POST /v1/chat/completions 或 POST /v1/responses。

请求参数

参数类型必填说明
modelstring必填目标模型名称(如 tengri-2),可用清单见 GET /v1/models
promptstring | string[]必填待续写提示文本;为保持跨模型一致性,建议传入单个字符串(避免传数字 token ID 数组)
max_tokensinteger可选最大续写输出 token 数(≥ 1)
temperaturenumber可选采样温度(0.0 ~ 2.0)
top_pnumber可选核采样概率阈值(0.0 ~ 1.0)
ninteger可选生成候选续写条数默认值1
streamboolean可选设为 true 返回 text_completion SSE 增量帧,末尾输出 data: [DONE]默认值false
stopstring | string[]可选停止词序列(最多 4 项)
echoboolean可选是否在输出中回显原始 prompt(部分模型支持)默认值false
suffixstring可选续写结果之后追加的后缀文本(部分模型支持)
presence_penaltynumber可选话题存在惩罚(-2.0 ~ 2.0)
frequency_penaltynumber可选词频重复惩罚(-2.0 ~ 2.0)
seedinteger可选随机种子
userstring可选调用方终端用户标识

响应示例(非流式)

JSON
{
  "id": "cmpl-20261128001",
  "object": "text_completion",
  "created": 1795853000,
  "model": "tengri-2",
  "choices": [
    {
      "text": "自上而下竖排书写,行序从左向右排列,是世界文字史上的独特瑰宝。",
      "index": 0,
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 11,
    "completion_tokens": 27,
    "total_tokens": 38
  }
}

示例(cURL / Python / Node.js)

Bash / cURL
curl -X POST "https://cloud.heimori.cn/v1/completions" \
  -H "Authorization: Bearer sk-heimori-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tengri-2",
    "prompt": "传统蒙古文的书写特点是:",
    "max_tokens": 256,
    "temperature": 0.4
  }'
Python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["XM_API_KEY"], base_url="https://cloud.heimori.cn/v1")
resp = client.completions.create(
    model="tengri-2",
    prompt="传统蒙古文的书写特点是:",
    max_tokens=256,
    temperature=0.4,
)
print(resp.choices[0].text)
JavaScript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.XM_API_KEY,
  baseURL: "https://cloud.heimori.cn/v1",
});
const resp = await client.completions.create({
  model: "tengri-2",
  prompt: "传统蒙古文的书写特点是:",
  max_tokens: 256,
});
console.log(resp.choices[0].text);

二、DashScope 兼容前缀(/compatible-mode/v1/*)

如果应用原已按照阿里云百炼 / DashScope OpenAI 兼容前缀(/compatible-mode/v1)封装,仅需将域名切换为 https://cloud.heimori.cn/compatible-mode/v1 并替换为讯蒙 API Key(sk-heimori-...),无需改动路径拼接逻辑。

完整挂载路由清单

方法兼容路径对应标准端点
GET/compatible-mode/v1/modelsGET /v1/models
GET/compatible-mode/v1/models/{model}GET /v1/models/{model}
POST/compatible-mode/v1/chat/completionsPOST /v1/chat/completions
POST/compatible-mode/v1/completionsPOST /v1/completions
POST/compatible-mode/v1/embeddingsPOST /v1/embeddings
POST/compatible-mode/v1/responsesPOST /v1/responses
POST/compatible-mode/v1/responses/input_tokensPOST /v1/responses/input_tokens
POST/compatible-mode/v1/messagesPOST /v1/messages
POST/compatible-mode/v1/messages/count_tokensPOST /v1/messages/count_tokens
POST/compatible-mode/v1/moderationsPOST /v1/moderations

迁移调用示例

Bash / cURL
curl -X POST "https://cloud.heimori.cn/compatible-mode/v1/chat/completions" \
  -H "Authorization: Bearer sk-heimori-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tengri-2",
    "messages": [{"role": "user", "content": "用蒙汉双语做自我介绍"}]
  }'
Python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["XM_API_KEY"],
    base_url="https://cloud.heimori.cn/compatible-mode/v1",
)
resp = client.chat.completions.create(
    model="tengri-2",
    messages=[{"role": "user", "content": "用蒙汉双语做自我介绍"}],
)
print(resp.choices[0].message.content)
JavaScript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.XM_API_KEY,
  baseURL: "https://cloud.heimori.cn/compatible-mode/v1",
});
const emb = await client.embeddings.create({
  model: "tengri-embedding-v1",
  input: ["ᠰᠠᠶᠢᠨ ᠪᠠᠶᠢᠨ᠎ᠠ ᠤᠤ", "你好,世界"],
});
console.log("向量维度:", emb.data[0].embedding.length);

三、账户余额与消费查询(OpenAI Billing 兼容)

用于兼容第三方客户端与聚合网关的查余额协议。全部账单查询接口不计费,且在账户余额为 0 时仍可正常调用(需已完成受信任机构准入或密钥白名单审批,且具备 chat 权限)。除 /v1/dashboard/billing/* 外,同步挂载根路径 /dashboard/billing/*。

端点列表

方法路径(及根路径别名)说明
GET/v1/dashboard/billing/subscription(/dashboard/billing/subscription)查询可用余额与总额度上限(原生密钥返回账户级余额,兼容令牌返回令牌级额度)
GET/v1/dashboard/billing/credit_grants(/dashboard/billing/credit_grants)返回与 subscription 完全一致的额度与余额快照
GET/v1/dashboard/billing/usage(/dashboard/billing/usage)按可选 UTC 日期区间查询当前单把密钥累计成功消费金额

1. subscription 与 credit_grants 响应字段(按密钥类型区分口径)

字段类型原生密钥(sk-heimori-...)有限额兼容令牌无限额兼容令牌
objectstring"billing_subscription""billing_subscription""billing_subscription"
has_payment_methodbooleantruetruetrue
soft_limit_usdnumber云账户可用余额 + 历史累计消费(保留 4 位小数,数值单位为元,保留协议字段名)该令牌剩余额度 + 已用额度(元)固定返回 100000000
hard_limit_usdnumber同 soft_limit_usd同 soft_limit_usd100000000
system_hard_limit_usdnumber同 soft_limit_usd同 soft_limit_usd100000000
access_untilinteger当前密钥到期 Unix 秒级时间戳(0 表示长期有效)当前令牌到期 Unix 秒级时间戳(0 表示长期有效)当前令牌到期 Unix 秒级时间戳(0 表示长期有效)
balance_yuannumber可选;云账户当前可用余额(元)可选;该令牌当前剩余额度(元)省略此字段

2. GET /v1/dashboard/billing/usage 请求参数(Query)

参数类型必填说明
start_datestring可选UTC 起始日期(格式 YYYY-MM-DD,含当天 00:00:00Z);不传时从密钥创建起累计;格式非法返回 400 invalid_date_range
end_datestring可选UTC 结束日期(格式 YYYY-MM-DD,含当天 23:59:59.999Z);不传时截至当前时刻

3. GET /v1/dashboard/billing/usage 响应字段

字段类型说明
objectstring固定为 list
total_usagenumber当前 API Key 在区间内成功调用的累计消费金额(单位:分,即 total_amount_yuan * 100,保留 4 位小数)
total_amount_yuannumber当前 API Key 在区间内成功调用的累计消费人民币金额(单位:元,保留 6 位小数)

示例(cURL / Python / Node.js)

Bash / cURL
# 1. 查询当前账户余额与总额度
curl "https://cloud.heimori.cn/v1/dashboard/billing/subscription" \
  -H "Authorization: Bearer sk-heimori-..."

# 2. 查询指定日期区间消费汇总
curl "https://cloud.heimori.cn/v1/dashboard/billing/usage?start_date=2026-11-01&end_date=2026-11-30" \
  -H "Authorization: Bearer sk-heimori-..."

# 3. 查询可用额度快照(credit_grants)
curl "https://cloud.heimori.cn/v1/dashboard/billing/credit_grants" \
  -H "Authorization: Bearer sk-heimori-..."

响应示例(GET /v1/dashboard/billing/subscription,原生密钥):

JSON
{
  "object": "billing_subscription",
  "has_payment_method": true,
  "soft_limit_usd": 1500,
  "hard_limit_usd": 1500,
  "system_hard_limit_usd": 1500,
  "access_until": 0,
  "balance_yuan": 1280.5
}

响应示例(GET /v1/dashboard/billing/usage?start_date=2026-11-01&end_date=2026-11-30):

JSON
{
  "object": "list",
  "total_usage": 21950,
  "total_amount_yuan": 219.5
}
Python
import os
import requests

headers = {"Authorization": f"Bearer {os.environ['XM_API_KEY']}"}

sub = requests.get(
    "https://cloud.heimori.cn/v1/dashboard/billing/subscription",
    headers=headers,
    timeout=10,
).json()
usage = requests.get(
    "https://cloud.heimori.cn/v1/dashboard/billing/usage",
    params={"start_date": "2026-11-01", "end_date": "2026-11-30"},
    headers=headers,
    timeout=10,
).json()
print("当前余额(元):", sub.get("balance_yuan"), "区间消费(元):", usage["total_amount_yuan"])
JavaScript
const headers = { Authorization: `Bearer ${process.env.XM_API_KEY}` };

const [subRes, usageRes] = await Promise.all([
  fetch("https://cloud.heimori.cn/v1/dashboard/billing/subscription", { headers }),
  fetch(
    "https://cloud.heimori.cn/v1/dashboard/billing/usage?start_date=2026-11-01&end_date=2026-11-30",
    { headers },
  ),
]);
console.log("Subscription:", await subRes.json());
console.log("Usage:", await usageRes.json());