> For the complete documentation index, see [llms.txt](https://ai-docs.akile.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai-docs.akile.ai/api-jie-ru/chat-completions.md).

# 聊天补全

AK AI Gateway 支持 OpenAI 兼容的聊天补全调用。大多数 OpenAI SDK 项目只需要替换 Base URL 和 API Key。

## 请求地址

```
POST https://aigateway.akile.ai/v1/chat/completions
```

## Python

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://aigateway.akile.ai/v1",
    api_key="AK-xxxxxxxx",
)

completion = client.chat.completions.create(
    model="claude-opus-4-8",
    messages=[
        {"role": "system", "content": "你是一个简洁的助手。"},
        {"role": "user", "content": "给我一个 API 网关的定义。"},
    ],
)

print(completion.choices[0].message.content)
```

## Node.js

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://aigateway.akile.ai/v1",
  apiKey: process.env.OPENAI_API_KEY,
});

const completion = await client.chat.completions.create({
  model: "claude-opus-4-8",
  messages: [
    { role: "user", content: "你好" },
  ],
});

console.log(completion.choices[0].message.content);
```

## curl

```bash
curl https://aigateway.akile.ai/v1/chat/completions \
  -H "Authorization: Bearer AK-xxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-8",
    "messages": [
      {"role": "user", "content": "你好"}
    ]
  }'
```

## 流式输出

如果 SDK 和模型支持流式输出，可以设置 `stream: true`：

```python
stream = client.chat.completions.create(
    model="claude-opus-4-8",
    messages=[{"role": "user", "content": "写一段短文"}],
    stream=True,
)

for event in stream:
    delta = event.choices[0].delta.content
    if delta:
        print(delta, end="")
```

## 模型名称

模型名称以控制台可用渠道页面为准。不同模型系列的参数支持程度可能不同，如果某个参数不生效或报错，先在控制台确认该模型和渠道是否可用。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ai-docs.akile.ai/api-jie-ru/chat-completions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
