docs/en/dev/openapi.md
Starting from v4.18.0, AstrBot provides API Key based HTTP APIs for programmatic access.
Authorization: Bearer abk_xxx
Also supported:
X-API-Key: abk_xxx
username is required:POST /api/v1/chat: request body must include usernameGET /api/v1/chat/sessions: query params must include usernameThe local OpenAPI schema is available at http://localhost:6185/api/v1/openapi.json, and the interactive docs are available at http://localhost:6185/api/v1/docs.
API Keys can be configured with scopes. See the API Scope–Endpoint Reference for each scope's purpose, inheritance rules, and complete endpoint list.
If the API Key does not include the required scope for the target endpoint, the request will return 403 Insufficient API key scope.
config is not selected by default in the WebUI and automatically includes bot and provider.config:edit_admin and chat:admin must be granted explicitly and are never inherited from their parent scopes.bot or provider in the WebUI also removes the dependent config scope.Developer API keys currently support 11 top-level scopes and two sensitive sub-scopes. tool, skills, kb, and system are not valid developer API key scopes. Use the singular skill scope for /api/v1/skills/* endpoints.
Every operation in the interactive reference also displays Required scope: ...; operations involving administrator capabilities additionally display Conditional sensitive scope: ....
Chat
Interact with AstrBot's built-in Agent. Supports plugin calls, tool calls, and other capabilities — consistent with IM-side chat.
POST /api/v1/chat: send chat message (SSE stream, server generates UUID when session_id is omitted)GET /api/v1/chat/sessions: list sessions for a specific username with paginationGET /api/v1/configs: list available config filesPOST /api/v1/file: upload an attachment for later use in message segmentsBots and Providers
GET /api/v1/bots: list bot/platform configurationsPOST /api/v1/bots: create a bot/platform configurationGET /api/v1/providers: list model provider configurationsGET /api/v1/provider-sources: list provider source configurationsPersonas, Plugins, MCP, and Skills
GET /api/v1/personas: list personasGET /api/v1/plugins: list pluginsGET /api/v1/mcp/servers: list MCP serversGET /api/v1/skills: list skillsProactive IM Messages
POST /api/v1/im/message: send a proactive message via UMOGET /api/v1/im/bots: list bot/platform IDsmessage Field Format (Important)The message field in POST /api/v1/chat and POST /api/v1/im/message supports two formats:
{
"message": "Hello"
}
{
"message": [
{ "type": "plain", "text": "Please see this file" },
{ "type": "file", "attachment_id": "9a2f8c72-e7af-4c0e-b352-111111111111" }
]
}
Supported type values:
| type | Required Fields | Optional Fields | Description |
|---|---|---|---|
plain | text | - | Text segment |
reply | message_id | selected_text | Quote-reply a message |
image | attachment_id | - | Image attachment segment |
record | attachment_id | - | Audio attachment segment |
file | attachment_id | - | Generic file segment |
video | attachment_id | - | Video attachment segment |
reply segment is currently only supported for /api/v1/chat, not for POST /api/v1/im/message.Notes:
attachment_id comes from an existing attachment record, or from POST /api/v1/file after uploading an attachment with the file scope.reply cannot be the only segment; at least one content segment (e.g. plain/image/file/...) is required.reply or empty content will return an error.message Usage in Chat APIPOST /api/v1/chat additionally requires username, with optional session_id (a UUID is auto-generated if omitted).
username is a caller-declared WebChat identity used as the message sender and session owner. A key with only chat is rejected when the value matches any configured administrator ID and is prevented from receiving an administrator role inside the message pipeline. The sensitive chat:admin sub-scope explicitly permits configured administrator IDs; it does not make arbitrary usernames administrators. Integrations should still map external users to stable, application-controlled usernames.
{
"username": "alice",
"session_id": "my_session_001",
"message": [
{ "type": "plain", "text": "Please summarize this PDF" },
{ "type": "file", "attachment_id": "9a2f8c72-e7af-4c0e-b352-111111111111" }
],
"enable_streaming": true
}
message Usage in IM Message APIPOST /api/v1/im/message requires umo + message.
{
"umo": "webchat:FriendMessage:openapi_probe",
"message": [
{ "type": "plain", "text": "This is a proactive message" },
{ "type": "image", "attachment_id": "9a2f8c72-e7af-4c0e-b352-222222222222" }
]
}
curl -N 'http://localhost:6185/api/v1/chat' \
-H 'Authorization: Bearer abk_xxx' \
-H 'Content-Type: application/json' \
-d '{"message":"Hello","username":"alice"}'
Use the interactive docs: