---
title: "OpenAI 对话"
method: POST
path: "/api/ai/chat/completions"
tags: ["AI 服务/大语言模型"]
---

# OpenAI 对话

`POST /api/ai/chat/completions`

## Request

- Base URL: `https://aitoearn.cn`
- URL: `https://aitoearn.cn/api/ai/chat/completions`
- Auth: API key in header `Authorization`
- TypeScript: <https://skmtc.dev/aitoearn/apis/aitoearn-api/docs/api/ai/chat/completions/post.ts> (a function with typed inputs; its response is checked against the schema)

接口说明：OpenAI Chat Completions API 的兼容端点，支持 `stream` 流式输出。请求、响应与错误格式完全遵循 OpenAI 规范；鉴权使用 `Authorization: Bearer <API Key>`（OpenAI SDK 默认携带），已有 OpenAI SDK 或生态工具只需替换 baseURL 与 API Key 即可接入，按 AiToEarn 积分计费。

调用本接口前，请先请求[「对话模型列表」](/api-reference/get-api-ai-models-chat)接口（`GET /api/ai/models/chat`），获取当前可用的模型列表。

## Request body

- RelayChatCompletionsDto
  - `messages` object[], required: 消息列表
    - `role` string, required: 消息角色，用于区分不同消息来源
    - `content` unknown, required
  - `model` string, required: 模型 ID。先调用[「对话模型列表」](/api-reference/get-api-ai-models-chat)接口（`GET /api/ai/models/chat`），传入其返回的 `data[n].name`。
  - `stream` boolean: 是否流式返回

## Response `200`

第三方协议原生响应或 SSE 数据。不使用 AiToEarn 通用响应包裹。

## Changes

- **2026-11-03** `7cc8f21c4c96`: 1 breaking, 1 info
  - the `messages/items/content` request property type changed from `string` to no type
  - the `stream` request property default value `false` was removed

[Operation history](https://skmtc.dev/aitoearn/apis/aitoearn-api/changes/api/ai/chat/completions/post.md)

---

[API](https://skmtc.dev/aitoearn/apis/aitoearn-api.md) - [All operations](https://skmtc.dev/aitoearn/apis/aitoearn-api/llms.txt) - [OpenAPI document](https://skmtc.dev/aitoearn/apis/aitoearn-api/revisions/7cc8f21c4c96?raw)
