文本补全
接口行为
要求 completion 部署,不发送 messages。
接口与认证
POST /v1/completions使用 XHub API 密钥:Authorization: Bearer 。不要把供应商密钥当作网关密钥。
Base URL 使用调试台显示的网关根地址,不额外追加 /v1;实际请求使用上面的完整接口路径。
请求示例
curl "$XHUB_BASE_URL/v1/completions" \
-H "Authorization: Bearer $XHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"YOUR_MODEL_NAME","prompt":"Write a short greeting.","max_tokens":64}'请求参数
| 字段 | 类型 | 说明 |
|---|---|---|
| model | string · required | 公开模型名,部署必须支持此协议。 |
| prompt | string or array · required | 文本补全提示词。 |
| max_tokens / temperature / stream | integer / number / boolean | 输出上限、采样和 SSE。 |
成功响应
{
"object": "text_completion",
"choices": [
{
"index": 0,
"text": "Hello!",
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 3,
"completion_tokens": 2,
"total_tokens": 5
}
}| 字段 | 类型 |
|---|---|
| object | string |
| choices | object[] |
| choices[].index | number |
| choices[].text | string |
| choices[].finish_reason | string |
| usage | object |
| usage.prompt_tokens | number |
| usage.completion_tokens | number |
| usage.total_tokens | number |
错误与排查
| HTTP | 说明 |
|---|---|
| 400 | 请求无效,请检查 JSON、参数和查询。 |
| 401 | XHub 凭据缺失或无效。 |
| 403 | 权限拒绝,请检查模型范围或策略。 |
| 429 | 超过限制,请检查响应详情与 Retry-After。 |