New document (#5299)

* add new doc (#5175)

Co-authored-by: dreamer6680 <146868355@qq.com>

* Test docs (#5235)

* fix: change the page of doc

* chore: add new dependencies, update global styles/layout, optimize docs, add Feishu & GitHub icons, update API examples

* fix: docs/index 404 not found

* Update environment variable names, optimize styles, add new API routes, fix component styles, adjust documentation, and update GitHub and Feishu icons

* update readme

* feat: add a linkfastgpt compontent

* feat: update new doc

* fix:remove unuse page and redirect homepage to docs (#5288)

* fix:remove some unuse doc

* fix: redirect homepage to doc

* git ignore

* fix:navbar to index (#5295)

* sidbar

* fix: navtab unlight (#5298)

* doc

---------

Co-authored-by: dreamer6680 <1468683855@qq.com>
Co-authored-by: dreamer6680 <146868355@qq.com>
This commit is contained in:
Archer
2025-07-23 21:35:03 +08:00
committed by GitHub
parent ce9ec1bf57
commit fe7abf22a9
895 changed files with 36297 additions and 56 deletions

View File

@@ -0,0 +1,79 @@
---
title: OpenAPI 介绍
description: FastGPT OpenAPI 介绍
---
## 使用说明
FasGPT OpenAPI 接口允许你使用 Api Key 进行鉴权,从而操作 FastGPT 上的相关服务和资源,例如:调用应用对话接口、上传知识库数据、搜索测试等等。出于兼容性和安全考虑,并不是所有的接口都允许通过 Api Key 访问。
## 如何查看 BaseURL
**注意BaseURL 不是接口地址,而是所有接口的根地址,直接请求 BaseURL 是没有用的。**
![](/imgs/fastgpt-api-baseurl.png)
## 如何获取 Api Key
FastGPT 的 API Key **有 2 类**,一类是全局通用的 key (无法直接调用应用对话);一类是携带了 AppId 也就是有应用标记的 key (可直接调用应用对话)。
我们建议,仅操作应用或者对话的相关接口使用 `应用特定key`,其他接口使用 `通用key`。
| 通用key | 应用特定 key |
| --------------------- | --------------------- |
| ![](/imgs/fastgpt-api2.jpg) | ![](/imgs/fastgpt-api1.jpg) |
## 基本配置
OpenAPI 中,所有的接口都通过 Header.Authorization 进行鉴权。
```
baseUrl: "https://api.fastgpt.in/api"
headers: {
Authorization: "Bearer {{apikey}}"
}
```
**发起应用对话示例**
```sh
curl --location --request POST 'https://api.fastgpt.in/api/v1/chat/completions' \
--header 'Authorization: Bearer fastgpt-xxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
"chatId": "111",
"stream": false,
"detail": false,
"messages": [
{
"content": "导演是谁",
"role": "user"
}
]
}'
```
## 自定义用户 ID
`v4.8.13`后支持传入自定义的用户 ID, 并且存入历史记录中。
```sh
curl --location --request POST 'https://api.fastgpt.in/api/v1/chat/completions' \
--header 'Authorization: Bearer fastgpt-xxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
"chatId": "111",
"stream": false,
"detail": false,
"messages": [
{
"content": "导演是谁",
"role": "user"
}
],
"customUid": "xxxxxx"
}'
```
在历史记录中,该条记录的使用者会显示为 `xxxxxx`。