Back to Fastgpt

OpenAPI Introduction

document/content/openapi/intro.en.mdx

4.15.03.5 KB
Original Source

Automated API Documentation

Starting with 4.15.0, FastGPT API docs are generated with zod-openapi. Some legacy endpoints have not been migrated yet, so they may not appear in the generated docs. Visit the generated API documentation URL to view the latest endpoint details. The manually maintained endpoint descriptions in the left-hand documentation are no longer updated.

FastGPT provides two generated API documents:

  • Dev API: all development APIs. Not every endpoint can be called with an API Key.
  • System OpenAPI: public endpoints that support API Key authentication.

API Documentation URLs

Use your FastGPT endpoint as the base URL and append the path below:

  • Dev API: {{endpoint}}/apidoc/devapi
  • System OpenAPI: {{endpoint}}/apidoc/systemopenapi

Cloud API Documentation URLs

Dev API:

System OpenAPI:

Usage Guide

FastGPT OpenAPI lets you authenticate with an API Key to access FastGPT services and resources -- such as calling app chat endpoints, uploading knowledge base data, search testing, and more. For compatibility and security reasons, not all endpoints support API Key access.

How to Find Your BaseURL

Note: BaseURL is not an endpoint address -- it's the root URL for all endpoints. Requesting the BaseURL directly won't work.

API Key

FastGPT uses a unified API Key model. API Keys are member credentials and are not bound to a single app.

  • For app-related endpoints other than chat/completions, pass appId explicitly in the request body or query.
  • For chat/completions, passing body.appId is recommended.
  • For OpenAI SDK compatibility, Authorization: Bearer <apiKey>-<appId> is also supported for chat/completions. The -<appId> suffix is only a transport compatibility format and is not stored.
  • Team owners can enable authProxy on an API Key to let chat/completions run as another team member. This does not skip app or chat permission checks.

Basic Configuration

In OpenAPI, all endpoints authenticate via Header.Authorization.

baseUrl: "http://localhost:3000/api"
headers: {
    Authorization: "Bearer {{apikey}}"
}

Example: Start an App Chat

sh
curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
--header 'Authorization: Bearer fastgpt-xxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "appId": "your_app_id",
    "chatId": "111",
    "stream": false,
    "detail": false,
    "messages": [
        {
            "content": "Who is the director",
            "role": "user"
        }
    ]
}'

Custom User ID

Since v4.8.13, you can pass a custom user ID that will be saved in the chat history.

sh
curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
--header 'Authorization: Bearer fastgpt-xxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "appId": "your_app_id",
    "chatId": "111",
    "stream": false,
    "detail": false,
    "messages": [
        {
            "content": "Who is the director",
            "role": "user"
        }
    ],
    "customUid": "xxxxxx"
}'

In the chat history, this record's user will be displayed as xxxxxx.