Repository navigation
en dev star guides plugin views web api
Standalone plugin pages and resident workbench pages call these endpoints through the Bridge. Message components and message-created workbench pages use @filter.ui_action; see Interactive message component.
Requests use the signed-in user's identity. Validate business permissions in the plugin. For session data, check ownership against request.username; a client-supplied session_id is not authorization.
Register plugin APIs with context.register_web_api(route, view_handler, methods, desc).
context.register_web_api(
f"/{PLUGIN_NAME}/items/<item_id>",
self.get_item,
["GET"],
"Get item",
)The registered route must include the plugin name prefix. The bridge endpoint used by the View does not include the plugin name:
await bridge.apiGet("items/123");The Dashboard forwards it to:
/api/v1/plugins/extensions/<plugin_name>/items/123
The registered route /<plugin_name>/items/<item_id> matches the request, and item_id is passed to the handler as a keyword argument:
async def get_item(self, item_id: str):
return json_response({"item_id": item_id})Supported dynamic segments:
-
<name>: matches one path segment. -
<path:name>: matches the remaining multi-segment path.
Recommended import:
from astrbot.api.web import requestrequest is a context proxy for the current request and is only available while a plugin Web API handler is running. Common fields and methods:
| API | Description |
|---|---|
request.method |
HTTP method, such as GET or POST
|
request.path |
Current Dashboard API path |
request.plugin_name |
Plugin name parsed from the extension path |
request.username |
Current Dashboard username, possibly None
|
request.headers |
Request headers |
request.cookies |
Request cookies |
request.content_type |
Request Content-Type |
request.client_host |
Client address |
request.path_params |
Dynamic route parameters |
request.query |
Query parameters with get() and getlist()
|
await request.body() |
Raw request body bytes |
await request.json(default={}) |
JSON body, returning default on parse failure |
await request.form() |
Form fields without uploaded files |
await request.files() |
Uploaded files |
Query example:
limit = request.query.get("limit", 20, type=int)
tags = request.query.getlist("tag")JSON example:
payload = await request.json(default={})
enabled = bool(payload.get("enabled"))Upload example:
from pathlib import Path
# Before AstrBot v4.30.0:
# from astrbot.core.utils.astrbot_path import get_astrbot_plugin_data_path
from astrbot.api.util import get_astrbot_plugin_data_path
from astrbot.api.web import PluginUploadFile, error_response, json_response, request
async def import_file(self):
form = await request.form()
files = await request.files()
upload: PluginUploadFile | None = files.get("file")
if not isinstance(upload, PluginUploadFile):
return error_response("missing file")
target_dir = (
Path(get_astrbot_plugin_data_path())
/ (request.plugin_name or "unknown_plugin")
/ "imports"
)
target_dir.mkdir(parents=True, exist_ok=True)
target = target_dir / Path(upload.filename).name
await upload.save(target)
return json_response(
{
"filename": upload.filename,
"content_type": upload.content_type,
"tag": form.get("tag"),
}
)request.form() and request.files() cache the parsed multipart data, so calling both in the same handler is fine.
Recommended response helpers:
from astrbot.api.web import (
error_response,
file_response,
json_response,
stream_response,
)JSON response:
return json_response({"saved": True})Error response:
return error_response("invalid threshold", status_code=400)File download response:
return file_response(
export_path,
filename="export.json",
content_type="application/json",
)SSE response:
import json
from astrbot.api.web import stream_response
async def stream_events(self):
async def events():
yield f"data: {json.dumps({'state': 'started'})}\n\n"
yield f"data: {json.dumps({'state': 'done'})}\n\n"
return stream_response(events())Returning a dict, list, (body, status_code), or a lower-level Response object still works. New plugins should prefer astrbot.api.web helpers so plugin code remains decoupled from the Dashboard's internal web framework.
For backward compatibility, handlers registered through context.register_web_api() still run inside a Quart-compatible request context. Existing plugins can continue to use:
from quart import jsonify, requestNew plugins and new documentation should use:
from astrbot.api.web import json_response, requestDo not mix the two request proxies in the same handler. Migrate one handler at a time.
- 首页
- 文档入口
- Top Level
- community events
- config
- deploy
- dev
- others
- platform
- 接入 OneBot v11 协议实现
- 接入钉钉 DingTalk
- 接入 Discord
- 接入 Kook
- 接入飞书
- 接入 LINE
- 接入 Matrix
- 接入 Mattermost
- 接入 Misskey 平台
- 接入 QQ 官方机器人平台
- 通过 QQ官方机器人 接入 QQ (Webhook)
- 通过 QQ官方机器人 接入 QQ (Websockets)
- 接入 Satori 协议
- 接入 server-satori (基于 Koishi)
- 接入 Slack
- 接入消息平台
- 接入 Telegram
- 接入 VoceChat
- AstrBot 接入企业微信
- 接入企业微信智能机器人平台
- AstrBot 接入微信公众平台
- 接入个人微信
- providers
- use
- Home
- Docs Entry
- Top Level
- config
- deploy
- Deploy AstrBot on 1Panel
- Deploy AstrBot on BT Panel
- Deploy AstrBot on CasaOS
- Deploy AstrBot from Source Code
- Community-Provided Deployment Methods
- Deploy via Compshare
- Deploy with AstrBot Desktop Client
- Deploy AstrBot with Docker
- Deploy AstrBot with Kubernetes
- Deploy AstrBot with AstrBot Launcher
- Other Deployments
- Script Deployment
- Installation via System Package Manager
- Preface
- dev
- AstrBot Configuration File
- API Scope–Endpoint Reference
- AstrBot HTTP API
- AstrBot Plugin Market JSON Specification
- Developing a Platform Adapter
- plugin
- AI
- Agents
- Sessions and Conversations
- Models
- Other APIs
- Tools
- Documentation moved
- Text to Image
- Handling Message Events
- Plugin Configuration
- Plugin Internationalization
- Documentation moved
- Shared Bridge API
- Interactive message component
- Standalone plugin page
- Backend Web APIs
- Workbench page
- Sending Messages
- Session Control
- Minimal Example
- Plugin Storage
- AstrBot Plugin Development Guide 🌠
- Publishing Plugins to the Plugin Marketplace
- ospp
- others
- platform
- Connect OneBot v11 Protocol Implementations
- Connect to DingTalk
- Connecting to Discord
- Connect to KOOK
- Connecting to Lark
- Connecting to LINE
- Connecting to Matrix
- Connecting to Mattermost
- Connecting to Misskey Platform
- Connect QQ Official Bot
- Connect QQ via QQ Official Bot (Webhook)
- Connect QQ via QQ Official Bot (Websockets)
- Connect to Satori Protocol
- Connect server-satori (Koishi)
- Connecting to Slack
- Messaging Platforms
- Connecting to Telegram
- Connect to VoceChat
- Connect AstrBot to WeCom
- Connect to WeCom AI Bot Platform
- Connect AstrBot to WeChat Official Account Platform
- Connect Personal WeChat
- providers
- Connect 302.AI
- Agent Runners
- Built-in Agent Runner
- Connect to Coze
- Connect to Alibaba Cloud Bailian Application
- Connect to DeerFlow
- Connect to Dify
- Connect AIHubMix
- coze
- dashscope
- DeepSeek STT Integration
- DeepSeek TTS Integration
- dify
- Model input images
- Large Language Model Providers
- Connect MiraRouter
- NewAPI
- Connect PPIO Cloud
- Connect LM Studio to Use DeepSeek-R1 and Other Models
- Integrating Ollama
- Connect ShengSuanYun
- Connecting to SiliconFlow
- Connecting Model Services
- Connecting to TokenPony
- use
- Agent Execution Mode {#agent-runner}
- Agent Sandbox Environment
- astrbot sandbox
- AstrBot CLI {#cli-commands}
- Docker-based Code Interpreter
- Built-in Commands
- computer
- Context Compression
- Session Configuration Mappings (formerly Custom Rules)
- AstrBot Knowledge Base
- MCP
- AstrBot Plugins {#astrbot-star}
- Proactive Capabilities
- Skills {#anthropic-skills}
- Subagents {#agent-handsoff-and-subagent}
- Unified Webhook Mode
- Web Search
- DeepSeek Search API
- SerpApi
- WebUI