API Key

POST /v1/chat/completions

API Key · POST /v1/chat/completions

Authentication

API Key. Session/administrative writes are not executed in the public Playground. Select a current model and replace example placeholders.

Endpoint

curl --request POST 'https://api.oneaster.ai/v1/chat/completions' \
  --header 'Authorization: Bearer '"$ONEASTER_API_KEY" \
  --header 'Idempotency-Key: '"$ONEASTER_INTENT" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "YOUR_TEXT_MODEL_ID",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "max_tokens": 64,
  "stream": false
}'

Parameters

- Idempotency-Key (header, Required): {"type":"string","minLength":1,"maxLength":100}

Request JSON Schema

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "model": {
      "type": "string"
    },
    "messages": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "role": {
            "enum": [
              "system",
              "user",
              "assistant"
            ]
          },
          "content": {
            "type": "string"
          }
        },
        "required": [
          "role",
          "content"
        ]
      },
      "minItems": 1,
      "maxItems": 128
    },
    "max_tokens": {
      "type": "integer",
      "minimum": 1,
      "maximum": 65536
    },
    "stream": {
      "type": "boolean"
    },
    "temperature": {
      "type": "number",
      "minimum": 0,
      "maximum": 2
    }
  },
  "required": [
    "model",
    "messages",
    "max_tokens"
  ]
}

Responses

200

OpenAI 兼容文本 Chat,JSON 与 SSE

{
  "application/json": {
    "schema": {}
  },
  "text/event-stream": {
    "schema": {
      "type": "string",
      "description": "data JSON 与 keepalive 注释,等待上游响应头期间也发送心跳。心跳提交 HTTP 200 后失败仍返回 SSE data error;开始流之前的错误返回 JSON。最终累计 usage 必须完整,部分最终帧不结算。PG 结算成功后发 [DONE];异常不发成功终止标记。缓存分类缺失为未知,不改变输入/输出售价。"
    }
  }
}

429

账户滚动 60 秒 300 RPM 限制;本次未新增预留或上游发送。

{
  "application/json": {
    "schema": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "success": {
          "const": false
        },
        "error": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "type": {
              "const": "oneaster_error"
            }
          },
          "required": [
            "code",
            "message",
            "type"
          ]
        },
        "data": {
          "type": "null"
        }
      },
      "required": [
        "success",
        "error",
        "data"
      ]
    }
  }
}

503

容量或后端不可用。若含 request ID 仍须查状态。

{
  "application/json": {
    "schema": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "success": {
          "const": false
        },
        "error": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "type": {
              "const": "oneaster_error"
            }
          },
          "required": [
            "code",
            "message",
            "type"
          ]
        },
        "data": {
          "type": "null"
        }
      },
      "required": [
        "success",
        "error",
        "data"
      ]
    }
  }
}

default

错误代码见 core-api.md;供应商/数据库错误已隐藏。

{
  "application/json": {
    "schema": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "success": {
          "const": false
        },
        "error": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "type": {
              "const": "oneaster_error"
            }
          },
          "required": [
            "code",
            "message",
            "type"
          ]
        },
        "data": {
          "type": "null"
        }
      },
      "required": [
        "success",
        "error",
        "data"
      ]
    }
  }
}