使用原生登录 access_token 直接扣减本人钱包调用 OpenAI 兼容 Chat JSON/SSE,不创建推理 Key,也不套用 facade 的 {data:...} 外壳。支持稳定 Idempotency-Key 持久化意图与断线恢复,禁用网关内部换渠道重试。
POST
/pg/chat/completions身份验证
Authorizationstring必填使用登录取得的 native access_token(身份要求:登录 access_token),按路由校验本人归属与受信任浏览器 Origin;生成写入按钱包规则扣费,只读查询不重新预扣;不得使用推理 API Key(sk-…)或 PAT(nap_…)。
Authorization: Bearer $ONEASTER_ACCESS_TOKEN
参数
Idempotency-Keystringheader · 每次新发起的 /pg 生成提交建议由前端生成并持久化稳定的 1–100 位无空格可打印 ASCII 标识(推荐 UUID),断线重试保持原标识与原请求字节。同账号跨所有 /pg POST 协议共用一个命名空间;省略时后端兼容生成并通过 X-OneAster-Intent-ID 返回,但若响应头丢失将无法按意图恢复。
请求正文 · application/json
modelstring必填模型 ID
messagesarray必填对话消息列表
temperaturenumber采样温度
top_pnumber核采样参数
ninteger生成数量
streamboolean是否流式响应
stream_optionsobjectstoponeOf停止序列
max_tokensinteger最大生成 Token 数
max_completion_tokensinteger最大补全 Token 数
presence_penaltynumberfrequency_penaltynumberlogit_biasobjectuserstringtoolsarraytool_choiceoneOfresponse_formatobjectseedintegerreasoning_effortstring推理强度 (用于支持推理的模型)
modalitiesarrayaudioobjectJSON Schema
{
"type": "object",
"required": [
"model",
"messages"
],
"properties": {
"model": {
"type": "string",
"description": "模型 ID",
"example": "gpt-4"
},
"messages": {
"type": "array",
"items": {
"type": "object",
"required": [
"role",
"content"
],
"properties": {
"role": {
"type": "string",
"enum": [
"system",
"user",
"assistant",
"tool",
"developer"
],
"description": "消息角色"
},
"content": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"text",
"image_url",
"input_audio",
"file",
"video_url"
]
},
"text": {
"type": "string"
},
"image_url": {
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "图片 URL 或 base64"
},
"detail": {
"type": "string",
"enum": [
"low",
"high",
"auto"
]
}
}
},
"input_audio": {
"type": "object",
"properties": {
"data": {
"type": "string",
"description": "Base64 编码的音频数据"
},
"format": {
"type": "string",
"enum": [
"wav",
"mp3"
]
}
}
},
"file": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"file_data": {
"type": "string"
},
"file_id": {
"type": "string"
}
}
},
"video_url": {
"type": "object",
"properties": {
"url": {
"type": "string"
}
}
}
}
}
}
],
"description": "消息内容"
},
"name": {
"type": "string",
"description": "发送者名称"
},
"tool_calls": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string",
"example": "function"
},
"function": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"arguments": {
"type": "string"
}
}
}
}
}
},
"tool_call_id": {
"type": "string",
"description": "工具调用 ID(用于 tool 角色消息)"
},
"reasoning_content": {
"type": "string",
"description": "推理内容"
}
}
},
"description": "对话消息列表"
},
"temperature": {
"type": "number",
"minimum": 0,
"maximum": 2,
"default": 1,
"description": "采样温度"
},
"top_p": {
"type": "number",
"minimum": 0,
"maximum": 1,
"default": 1,
"description": "核采样参数"
},
"n": {
"type": "integer",
"minimum": 1,
"default": 1,
"description": "生成数量"
},
"stream": {
"type": "boolean",
"default": false,
"description": "是否流式响应"
},
"stream_options": {
"type": "object",
"properties": {
"include_usage": {
"type": "boolean"
}
}
},
"stop": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
],
"description": "停止序列"
},
"max_tokens": {
"type": "integer",
"description": "最大生成 Token 数"
},
"max_completion_tokens": {
"type": "integer",
"description": "最大补全 Token 数"
},
"presence_penalty": {
"type": "number",
"minimum": -2,
"maximum": 2,
"default": 0
},
"frequency_penalty": {
"type": "number",
"minimum": -2,
"maximum": 2,
"default": 0
},
"logit_bias": {
"type": "object",
"additionalProperties": {
"type": "number"
},
"properties": {}
},
"user": {
"type": "string"
},
"tools": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "function"
},
"function": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"parameters": {
"type": "object",
"description": "JSON Schema 格式的参数定义",
"properties": {}
}
}
}
}
}
},
"tool_choice": {
"oneOf": [
{
"type": "string",
"enum": [
"none",
"auto",
"required"
]
},
{
"type": "object",
"properties": {
"type": {
"type": "string"
},
"function": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
}
}
]
},
"response_format": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"text",
"json_object",
"json_schema"
]
},
"json_schema": {
"type": "object",
"description": "JSON Schema 定义",
"properties": {}
}
}
},
"seed": {
"type": "integer"
},
"reasoning_effort": {
"type": "string",
"enum": [
"low",
"medium",
"high"
],
"description": "推理强度 (用于支持推理的模型)"
},
"modalities": {
"type": "array",
"items": {
"type": "string",
"enum": [
"text",
"audio"
]
}
},
"audio": {
"type": "object",
"properties": {
"voice": {
"type": "string"
},
"format": {
"type": "string"
}
}
}
}
}