> For the complete documentation index, see [llms.txt](https://docs.duckagi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.duckagi.com/duckagi-jie-ru-wen-dang-zhong-wen-ban.md).

# DuckAGI接入文档（中文版）

接入方式和OpenAI的一致。[点击前往OpenAI开发者平台](https://platform.openai.com/docs/guides/text-generation/chat-completions-api)

##

## 在官方OpenAI库中使用（python）

```
openai.api_base = 'https://api.duckagi.com/v1'
openai.api_key = 'sk-xxxxxxxxxxx'

messages = [
    {"role": "user", "content": "你好"}
]

res = openai.ChatCompletion.create(
    model="gpt-4",
    messages=messages,
    stream=False,
)

print(res['choices'][0]['message']['content'])
```

## DALL-E

```
openai.api_base = 'https://api.duckagi.com/v1'
openai.api_key = 'sk-xxxxxxxxxxx'

res = openai.Image.create(
    prompt='Cat'
)
print(res)
```

1、生成令牌

<figure><img src="/files/y0tmE15umdgPS6MxPM7m" alt=""><figcaption></figcaption></figure>

2.在聊天栏目的设置中填入信息进行测试

<figure><img src="/files/oncVHFOUfHdjt2bCGtSN" alt=""><figcaption></figcaption></figure>

3.成功

<figure><img src="/files/HQIdth0xH1GYhrlWQmc2" alt=""><figcaption></figcaption></figure>


---

# 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:

```
GET https://docs.duckagi.com/duckagi-jie-ru-wen-dang-zhong-wen-ban.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
