Skip to content

Commit 17f1b7f

Browse files
docs(api): improve public API reference documentation (#1068)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2509133 commit 17f1b7f

File tree

5 files changed

+94
-21
lines changed

5 files changed

+94
-21
lines changed

CLAUDE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ className="border-[var(--border)] bg-[var(--card)] text-[var(--foreground)]"
7171

7272
## API Route Handlers
7373

74+
When implementing a new API route, ask the user whether it should be part of the public API. If yes:
75+
76+
1. Add the request/response Zod schemas to `packages/web/src/openapi/publicApiSchemas.ts`, calling `.openapi('SchemaName')` on each schema to register it with a name.
77+
2. Register the route in `packages/web/src/openapi/publicApiDocument.ts` using `registry.registerPath(...)`, assigning it to the appropriate tag.
78+
3. Add the endpoint to the relevant group in the `API Reference` tab of `docs/docs.json`.
79+
4. Regenerate the OpenAPI spec by running `yarn workspace @sourcebot/web openapi:generate`.
80+
7481
Route handlers should validate inputs using Zod schemas.
7582

7683
**Query parameters** (GET requests):

docs/api-reference/sourcebot-public.openapi.json

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@
2323
"description": "System health and version endpoints."
2424
},
2525
{
26-
"name": "User Management (EE)",
27-
"description": "User management endpoints. Requires the `org-management` entitlement and OWNER role."
28-
},
29-
{
30-
"name": "Audit (EE)",
31-
"description": "Audit log endpoints. Requires the `audit` entitlement and OWNER role."
26+
"name": "Enterprise (EE)",
27+
"description": "Enterprise endpoints for user management and audit logging."
3228
}
3329
],
3430
"security": [
@@ -1100,13 +1096,13 @@
11001096
"bearerToken": {
11011097
"type": "http",
11021098
"scheme": "bearer",
1103-
"description": "Send either a Sourcebot API key (`sbk_...`) or, on EE instances with OAuth enabled, an OAuth access token (`sboa_...`) in the Authorization header."
1099+
"description": "Bearer authentication header of the form `Bearer <token>`, where `<token>` is your API key."
11041100
},
11051101
"apiKeyHeader": {
11061102
"type": "apiKey",
11071103
"in": "header",
11081104
"name": "X-Sourcebot-Api-Key",
1109-
"description": "Send a Sourcebot API key (`sbk_...`) in the X-Sourcebot-Api-Key header."
1105+
"description": "Header of the form `X-Sourcebot-Api-Key: <token>`, where `<token>` is your API key."
11101106
}
11111107
}
11121108
},
@@ -1828,10 +1824,13 @@
18281824
"get": {
18291825
"operationId": "getUser",
18301826
"tags": [
1831-
"User Management (EE)"
1827+
"Enterprise (EE)"
18321828
],
18331829
"summary": "Get a user",
18341830
"description": "Fetches profile details for a single organization member by `userId`. Only organization owners can access this endpoint.",
1831+
"x-mint": {
1832+
"content": "<Note>\nThis API is only available with an active Enterprise license. Please add your [license key](/docs/license-key) to activate it.\n</Note>"
1833+
},
18351834
"parameters": [
18361835
{
18371836
"schema": {
@@ -1900,10 +1899,13 @@
19001899
"delete": {
19011900
"operationId": "deleteUser",
19021901
"tags": [
1903-
"User Management (EE)"
1902+
"Enterprise (EE)"
19041903
],
19051904
"summary": "Delete a user",
19061905
"description": "Permanently deletes a user and all associated records. Only organization owners can delete other users.",
1906+
"x-mint": {
1907+
"content": "<Note>\nThis API is only available with an active Enterprise license. Please add your [license key](/docs/license-key) to activate it.\n</Note>"
1908+
},
19071909
"parameters": [
19081910
{
19091911
"schema": {
@@ -1974,10 +1976,13 @@
19741976
"get": {
19751977
"operationId": "listUsers",
19761978
"tags": [
1977-
"User Management (EE)"
1979+
"Enterprise (EE)"
19781980
],
19791981
"summary": "List users",
19801982
"description": "Returns all members of the organization. Only organization owners can access this endpoint.",
1983+
"x-mint": {
1984+
"content": "<Note>\nThis API is only available with an active Enterprise license. Please add your [license key](/docs/license-key) to activate it.\n</Note>"
1985+
},
19811986
"responses": {
19821987
"200": {
19831988
"description": "List of organization members.",
@@ -2016,10 +2021,13 @@
20162021
"get": {
20172022
"operationId": "listAuditRecords",
20182023
"tags": [
2019-
"Audit (EE)"
2024+
"Enterprise (EE)"
20202025
],
20212026
"summary": "List audit records",
20222027
"description": "Returns a paginated list of audit log entries. Only organization owners can access this endpoint.",
2028+
"x-mint": {
2029+
"content": "<Note>\nThis API is only available with an active Enterprise license. Please add your [license key](/docs/license-key) to activate it.\n</Note>"
2030+
},
20232031
"parameters": [
20242032
{
20252033
"schema": {

docs/docs.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@
145145
"icon": "code",
146146
"openapi": "api-reference/sourcebot-public.openapi.json",
147147
"groups": [
148+
{
149+
"group": "Overview",
150+
"icon": "book-open",
151+
"pages": [
152+
"docs/api-reference/authentication"
153+
]
154+
},
148155
{
149156
"group": "Search & Navigation",
150157
"icon": "magnifying-glass",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: "Authentication"
3+
---
4+
5+
To securely access and interact with Sourcebot’s API, authentication is required. Users must generate an API Key, which will be used to authenticate requests.
6+
7+
<Note>
8+
If [anonymous access](/docs/configuration/auth/access-settings#anonymous-access) is enabled, some endpoints will be accessible without a API key.
9+
</Note>
10+
11+
## Creating an API key
12+
13+
Navigate to **Settings → API Keys** and click **Create API Key**. Copy the value - it is only shown once.
14+
15+
<Frame>
16+
<img src="/images/mcp_api_key_settings.png" alt="API Keys page in Sourcebot Settings" />
17+
</Frame>
18+
19+
## Using an API key
20+
21+
Pass your API key as a Bearer token in the `Authorization` header on every request.
22+
23+
```bash
24+
Authorization: Bearer <your-api-key>
25+
```
26+
27+
For example, to call the `/api/search` endpoint:
28+
29+
```bash
30+
curl -X POST https://your-sourcebot-instance.com/api/search \
31+
-H "Authorization: Bearer <your-api-key>" \
32+
-H "Content-Type: application/json" \
33+
-d '{"query": "hello world", "matches": 10}'
34+
```

packages/web/src/openapi/publicApiDocument.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ const searchTag = { name: 'Search & Navigation', description: 'Code search and s
3131
const reposTag = { name: 'Repositories', description: 'Repository listing and metadata endpoints.' };
3232
const gitTag = { name: 'Git', description: 'Git history, diff, and file content endpoints.' };
3333
const systemTag = { name: 'System', description: 'System health and version endpoints.' };
34-
const eeUserManagementTag = { name: 'User Management (EE)', description: 'User management endpoints. Requires the `org-management` entitlement and OWNER role.' };
35-
const eeAuditTag = { name: 'Audit (EE)', description: 'Audit log endpoints. Requires the `audit` entitlement and OWNER role.' };
34+
const eeTag = { name: 'Enterprise (EE)', description: 'Enterprise endpoints for user management and audit logging.' };
35+
36+
const EE_LICENSE_KEY_NOTE = dedent`
37+
<Note>
38+
This API is only available with an active Enterprise license. Please add your [license key](/docs/license-key) to activate it.
39+
</Note>
40+
`;
3641

3742
const publicFileTreeNodeSchema: SchemaObject = {
3843
type: 'object',
@@ -67,13 +72,13 @@ const securitySchemes: Record<keyof typeof securitySchemeNames, SecuritySchemeOb
6772
[securitySchemeNames.bearerToken]: {
6873
type: 'http',
6974
scheme: 'bearer',
70-
description: 'Send either a Sourcebot API key (`sbk_...`) or, on EE instances with OAuth enabled, an OAuth access token (`sboa_...`) in the Authorization header.',
75+
description: 'Bearer authentication header of the form `Bearer <token>`, where `<token>` is your API key.',
7176
},
7277
[securitySchemeNames.apiKeyHeader]: {
7378
type: 'apiKey',
7479
in: 'header',
7580
name: 'X-Sourcebot-Api-Key',
76-
description: 'Send a Sourcebot API key (`sbk_...`) in the X-Sourcebot-Api-Key header.',
81+
description: 'Header of the form `X-Sourcebot-Api-Key: <token>`, where `<token>` is your API key.',
7782
},
7883
};
7984

@@ -339,7 +344,7 @@ export function createPublicOpenApiDocument(version: string) {
339344
method: 'get',
340345
path: '/api/ee/user',
341346
operationId: 'getUser',
342-
tags: [eeUserManagementTag.name],
347+
tags: [eeTag.name],
343348
summary: 'Get a user',
344349
description: 'Fetches profile details for a single organization member by `userId`. Only organization owners can access this endpoint.',
345350
request: {
@@ -357,13 +362,16 @@ export function createPublicOpenApiDocument(version: string) {
357362
404: errorJson('User not found.'),
358363
500: errorJson('Unexpected failure.'),
359364
},
365+
'x-mint': {
366+
content: EE_LICENSE_KEY_NOTE,
367+
},
360368
});
361369

362370
registry.registerPath({
363371
method: 'delete',
364372
path: '/api/ee/user',
365373
operationId: 'deleteUser',
366-
tags: [eeUserManagementTag.name],
374+
tags: [eeTag.name],
367375
summary: 'Delete a user',
368376
description: 'Permanently deletes a user and all associated records. Only organization owners can delete other users.',
369377
request: {
@@ -381,13 +389,16 @@ export function createPublicOpenApiDocument(version: string) {
381389
404: errorJson('User not found.'),
382390
500: errorJson('Unexpected failure.'),
383391
},
392+
'x-mint': {
393+
content: EE_LICENSE_KEY_NOTE,
394+
},
384395
});
385396

386397
registry.registerPath({
387398
method: 'get',
388399
path: '/api/ee/users',
389400
operationId: 'listUsers',
390-
tags: [eeUserManagementTag.name],
401+
tags: [eeTag.name],
391402
summary: 'List users',
392403
description: 'Returns all members of the organization. Only organization owners can access this endpoint.',
393404
responses: {
@@ -398,14 +409,17 @@ export function createPublicOpenApiDocument(version: string) {
398409
403: errorJson('Insufficient permissions or entitlement not enabled.'),
399410
500: errorJson('Unexpected failure.'),
400411
},
412+
'x-mint': {
413+
content: EE_LICENSE_KEY_NOTE,
414+
},
401415
});
402416

403417
// EE: Audit
404418
registry.registerPath({
405419
method: 'get',
406420
path: '/api/ee/audit',
407421
operationId: 'listAuditRecords',
408-
tags: [eeAuditTag.name],
422+
tags: [eeTag.name],
409423
summary: 'List audit records',
410424
description: 'Returns a paginated list of audit log entries. Only organization owners can access this endpoint.',
411425
request: {
@@ -430,6 +444,9 @@ export function createPublicOpenApiDocument(version: string) {
430444
403: errorJson('Insufficient permissions or entitlement not enabled.'),
431445
500: errorJson('Unexpected failure.'),
432446
},
447+
'x-mint': {
448+
content: EE_LICENSE_KEY_NOTE,
449+
},
433450
});
434451

435452
const generator = new OpenApiGeneratorV3(registry.definitions);
@@ -441,7 +458,7 @@ export function createPublicOpenApiDocument(version: string) {
441458
version,
442459
description: 'OpenAPI description for the public Sourcebot REST endpoints used for search, repository listing, and file browsing. Authentication is instance-dependent: API keys are the standard integration mechanism, OAuth bearer tokens are EE-only, and some instances may allow anonymous access.',
443460
},
444-
tags: [searchTag, reposTag, gitTag, systemTag, eeUserManagementTag, eeAuditTag],
461+
tags: [searchTag, reposTag, gitTag, systemTag, eeTag],
445462
security: [
446463
{ [securitySchemeNames.bearerToken]: [] },
447464
{ [securitySchemeNames.apiKeyHeader]: [] },

0 commit comments

Comments
 (0)