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

# OpenAI 对话

`POST /api/ai/chat/completions`

接口说明：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` string, 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 通用响应包裹。

- object — 第三方协议原生响应，不使用 AiToEarn 通用响应包裹。

---

[API](https://skmtc.net/aitoearn/apis/aitoearn-api.md) · [All operations](https://skmtc.net/aitoearn/apis/aitoearn-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/aitoearn/aitoearn-api/revisions/19d860d9260d/schema)
