Skip to content

Commit 29a388a

Browse files
committed
feat: add vitepress-openapi dependency and create OpenAPI documentation
- Added vitepress-openapi as a dependency in package.json. - Updated pnpm-lock.yaml to include vitepress-openapi and its dependencies. - Created a new scalar.html file for the AstrBot OpenAPI interface. - Added Chinese documentation for the AstrBot HTTP API, detailing usage, scopes, and examples.
1 parent 24aa577 commit 29a388a

File tree

8 files changed

+807
-5
lines changed

8 files changed

+807
-5
lines changed

.vitepress/config.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default defineConfig({
2828
{ text: "开始", link: "/what-is-astrbot" },
2929
{ text: "博客", link: "https://blog.astrbot.app" },
3030
{ text: "路线图", link: "https://astrbot.featurebase.app/roadmap" },
31+
{ text: "HTTP API", link: "https://docs.astrbot.app/scalar.html" },
3132
],
3233
sidebar: [
3334
{
@@ -204,6 +205,10 @@ export default defineConfig({
204205
text: "接入平台适配器",
205206
link: "/plugin-platform-adapter",
206207
},
208+
{
209+
text: "AstrBot HTTP API",
210+
link: "/openapi",
211+
},
207212
],
208213
},
209214
{
@@ -256,6 +261,7 @@ export default defineConfig({
256261
nav: [
257262
{ text: "Home", link: "/en/" },
258263
{ text: "Get Started", link: "/en/what-is-astrbot" },
264+
{ text: "HTTP API", link: "https://docs.astrbot.app/scalar.html" },
259265
],
260266
sidebar: [
261267
{
@@ -425,6 +431,10 @@ export default defineConfig({
425431
text: "Platform Adapter Integration",
426432
link: "/plugin-platform-adapter",
427433
},
434+
{
435+
text: "AstrBot HTTP API",
436+
link: "/openapi",
437+
},
428438
],
429439
},
430440
{

.vitepress/theme/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
// https://vitepress.dev/guide/custom-theme
22
import { h } from 'vue'
33
import DefaultTheme from 'vitepress/theme'
4+
import { theme as openapiTheme, useOpenapi } from 'vitepress-openapi/client'
5+
import 'vitepress-openapi/dist/style.css'
6+
import openapiSpec from '../../public/openapi.json'
47
import './styles/style.css'
58
import './styles/custom-block.css'
69
import './styles/font.css'
7-
import ArticleShare from "./components/ArticleShare.vue";
10+
import ArticleShare from './components/ArticleShare.vue'
811
import NotFound from './components/NotFound.vue'
912

1013
/** @type {import('vitepress').Theme} */
1114
export default {
1215
extends: DefaultTheme,
16+
enhanceApp(ctx) {
17+
openapiTheme.enhanceApp(ctx)
18+
useOpenapi({
19+
app: ctx.app,
20+
spec: openapiSpec
21+
})
22+
},
1323
Layout() {
1424
return h(DefaultTheme.Layout, null, {
1525
// https://vitepress.dev/guide/extending-default-theme#layout-slots
16-
"aside-outline-after": () => h(ArticleShare),
17-
"not-found": () => h(NotFound),
26+
'aside-outline-after': () => h(ArticleShare),
27+
'not-found': () => h(NotFound)
1828
})
1929
}
2030
}

en/dev/openapi.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# AstrBot HTTP API
6+
7+
Starting from v4.18.0, AstrBot provides API Key based HTTP APIs for programmatic access.
8+
9+
## Quick Start
10+
11+
1. Create an API key in WebUI.
12+
2. Include the API key in request headers:
13+
14+
```http
15+
Authorization: Bearer abk_xxx
16+
```
17+
18+
Also supported:
19+
20+
```http
21+
X-API-Key: abk_xxx
22+
```
23+
24+
3. For chat endpoints, `username` is required:
25+
26+
- `POST /api/v1/chat`: request body must include `username`
27+
- `GET /api/v1/chat/sessions`: query params must include `username`
28+
29+
## Common Endpoints
30+
31+
- `POST /api/v1/chat`: send chat message (SSE stream, server generates UUID when `session_id` is omitted)
32+
- `GET /api/v1/chat/sessions`: list sessions for a specific `username` with pagination
33+
- `GET /api/v1/configs`: list available config files
34+
- `POST /api/v1/file`: upload attachment
35+
- `POST /api/v1/im/message`: proactive message via UMO
36+
- `GET /api/v1/im/bots`: list bot/platform IDs
37+
38+
## Example
39+
40+
```bash
41+
curl -N 'http://localhost:6185/api/v1/chat' \
42+
-H 'Authorization: Bearer abk_xxx' \
43+
-H 'Content-Type: application/json' \
44+
-d '{"message":"Hello","username":"alice"}'
45+
```
46+
47+
## Full API Reference
48+
49+
Use the interactive docs:
50+
51+
- https://docs.astrbot.app/scalar.html

0 commit comments

Comments
 (0)