Skip to content

Commit 390d95e

Browse files
fylornclaude
andcommitted
docs: sync all documentation for new providers, endpoints, and config guide
Update 12 documentation files (6 English, 6 Chinese) to reflect: - Six providers: OpenAI, Anthropic, Google Gemini, Azure OpenAI, AWS Bedrock, Custom - Three API formats: /v1/chat/completions, /v1/messages, /v1/responses - Provider auto-loading with default model prefixes - AWS SigV4 signing and binary event-stream streaming for Bedrock - Built-in Configuration Guide page (/gateway/guide) - Azure OpenAI deployment URL pattern and api-key auth - Full API reference for /v1/messages and /v1/responses endpoints Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f681e30 commit 390d95e

12 files changed

Lines changed: 688 additions & 50 deletions

‎README.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Just as an SSH bastion host is the single gateway through which all server acces
2020
Claude Code ──────>│ │──> OpenAI
2121
Cursor ───────────>│ Gateway :3000 │──> Anthropic
2222
Custom Agent ─────>│ AI API + MCP Unified Proxy │──> Google Gemini
23-
CI/CD Pipeline ───>│ │──> Self-hosted LLMs
23+
CI/CD Pipeline ───>│ │──> Azure OpenAI / AWS Bedrock
2424
└──────────────────────────────────────┘
2525
┌──────────────────────────────────────┐
2626
Admin Browser ────>│ Console :3001 │
@@ -43,9 +43,10 @@ AgentBastion solves all of this with a single deployment.
4343
## Key Features
4444

4545
### AI API Gateway
46-
- **OpenAI-compatible proxy** — drop-in replacement; point `OPENAI_BASE_URL` at AgentBastion and go
47-
- **Multi-provider routing** — OpenAI, Anthropic, Google Gemini, Azure, or any OpenAI-compatible endpoint
48-
- **Automatic format conversion** — Anthropic Messages API, Google Gemini, and more, all behind a single OpenAI-compatible interface
46+
- **Multi-format API proxy** — natively serves OpenAI Chat Completions (`/v1/chat/completions`), Anthropic Messages (`/v1/messages`), and OpenAI Responses (`/v1/responses`) APIs on a single port; works as a drop-in replacement for Cursor, Continue, Cline, Claude Code, and the OpenAI/Anthropic SDKs
47+
- **Multi-provider routing** — OpenAI, Anthropic, Google Gemini, Azure OpenAI, AWS Bedrock, or any OpenAI-compatible endpoint
48+
- **Automatic format conversion** — Anthropic Messages API, Google Gemini, Azure OpenAI, AWS Bedrock Converse API, and more, all behind a unified interface
49+
- **Provider auto-loading** — active providers are loaded from the database at startup and registered in the model router; default model prefixes (`gpt-`/`o1-`/`o3-`/`o4-` for OpenAI, `claude-` for Anthropic, `gemini-` for Google) route automatically; Azure and Bedrock require explicit model registration
4950
- **Streaming SSE pass-through** — zero-overhead forwarding with real-time token counting
5051
- **Virtual API keys** — issue scoped `ab-` keys per team, per project, per developer; revoke in one click
5152
- **API key lifecycle management** — automatic rotation with grace periods, per-key inactivity timeout, expiry warnings, and background policy enforcement
@@ -77,6 +78,7 @@ AgentBastion solves all of this with a single deployment.
7778
### Operations & Configuration
7879
- **Dynamic configuration** — most settings stored in database (`system_settings` table), configurable via Web UI (Admin > Settings with 7 category tabs)
7980
- **First-run setup wizard** — guided `/setup` wizard creates the super_admin account, configures the site, and optionally adds the first provider and API key
81+
- **Configuration Guide** — built-in `/gateway/guide` page in the web console with copy-paste setup instructions for Claude Code, Cursor, Continue, Cline, OpenAI SDK, Anthropic SDK, and cURL; auto-detects the gateway URL
8082
- **Multi-instance sync** — configuration changes propagated across instances via Redis Pub/Sub
8183
- **Data retention policies** — configurable retention periods for usage records and audit logs with automatic daily purge
8284

@@ -134,7 +136,7 @@ See the **[Deployment Guide](docs/en/deployment-guide.md)** for production setup
134136

135137
| Port | Server | Exposure | Purpose |
136138
|------|--------|----------|---------|
137-
| `3000` | Gateway | **Public** — expose to AI clients | `/v1/chat/completions`, `/v1/models`, `/mcp`, `/metrics`, `/health/*` |
139+
| `3000` | Gateway | **Public** — expose to AI clients | `/v1/chat/completions`, `/v1/messages`, `/v1/responses`, `/v1/models`, `/mcp`, `/metrics`, `/health/*` |
138140
| `3001` | Console | **Internal** — behind VPN/firewall | `/api/*` management endpoints, Web UI |
139141

140142
> In production, **only port 3000** should be reachable from the internet. Port 3001 should be restricted to your admin network.

‎README.zh-CN.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Claude Code ──────>│ │──> OpenAI
2121
Cursor ───────────>│ Gateway :3000 │──> Anthropic
2222
自定义 Agent ─────>│ AI API + MCP 统一代理 │──> Google Gemini
23-
CI/CD 流水线 ─────>│ │──> 私有化部署 LLM
23+
CI/CD 流水线 ─────>│ │──> Azure OpenAI / AWS Bedrock
2424
└──────────────────────────────────────┘
2525
┌──────────────────────────────────────┐
2626
管理员浏览器 ─────>│ Console :3001 │
@@ -43,9 +43,10 @@ AgentBastion 一次部署,全部解决。
4343
## 核心功能
4444

4545
### AI API 网关
46-
- **OpenAI 兼容代理** — 直接替换;将 `OPENAI_BASE_URL` 指向 AgentBastion 即可使用
47-
- **多 Provider 路由** — OpenAI、Anthropic、Google Gemini、Azure 或任何 OpenAI 兼容端点
48-
- **自动格式转换** — Anthropic Messages API、Google Gemini 等,统一在 OpenAI 兼容接口之后
46+
- **多格式 API 代理** — 在同一端口原生支持 OpenAI Chat Completions (`/v1/chat/completions`)、Anthropic Messages (`/v1/messages`) 和 OpenAI Responses (`/v1/responses`) API;可直接替换 Cursor、Continue、Cline、Claude Code 以及 OpenAI/Anthropic SDK
47+
- **多 Provider 路由** — OpenAI、Anthropic、Google Gemini、Azure OpenAI、AWS Bedrock 或任何 OpenAI 兼容端点
48+
- **自动格式转换** — Anthropic Messages API、Google Gemini、Azure OpenAI、AWS Bedrock Converse API 等,统一在同一接口之后
49+
- **Provider 自动加载** — 启动时从数据库加载所有活跃 Provider 并注册到模型路由器;默认模型前缀(`gpt-`/`o1-`/`o3-`/`o4-` 对应 OpenAI,`claude-` 对应 Anthropic,`gemini-` 对应 Google)自动路由;Azure 和 Bedrock 需要显式注册模型
4950
- **SSE 流式透传** — 零开销转发,实时 Token 计数
5051
- **虚拟 API Key** — 按团队、项目、开发者签发 `ab-` 前缀的作用域密钥,一键吊销
5152
- **API Key 生命周期管理** — 自动轮换并支持宽限期、按 Key 的闲置超时、到期预警、后台策略执行
@@ -77,6 +78,7 @@ AgentBastion 一次部署,全部解决。
7778
### 运维与配置
7879
- **动态配置** — 大部分配置存储在数据库(`system_settings` 表),可通过 Web UI(管理 > 设置,7 个分类标签页)配置
7980
- **首次运行向导** — 引导式 `/setup` 向导,创建超级管理员账户、配置站点信息,可选添加首个 Provider 和 API Key
81+
- **配置指南** — Web 控制台内置 `/gateway/guide` 页面,提供 Claude Code、Cursor、Continue、Cline、OpenAI SDK、Anthropic SDK 和 cURL 的一键复制配置说明;自动检测网关 URL
8082
- **多实例同步** — 配置变更通过 Redis Pub/Sub 在多个实例间同步
8183
- **数据保留策略** — 可配置使用记录和审计日志的保留期限,每日自动清理
8284

@@ -134,7 +136,7 @@ cd web && pnpm install && pnpm dev
134136

135137
| 端口 | 服务器 | 暴露范围 | 用途 |
136138
|------|--------|----------|------|
137-
| `3000` | Gateway | **公网** — 暴露给 AI 客户端 | `/v1/chat/completions`, `/v1/models`, `/mcp`, `/metrics`, `/health/*` |
139+
| `3000` | Gateway | **公网** — 暴露给 AI 客户端 | `/v1/chat/completions`, `/v1/messages`, `/v1/responses`, `/v1/models`, `/mcp`, `/metrics`, `/health/*` |
138140
| `3001` | Console | **内网** — 限制在 VPN/防火墙后 | `/api/*` 管理端点, Web UI |
139141

140142
> 生产环境中,**仅端口 3000** 应可从公网访问。端口 3001 应限制在管理网络内。

‎docs/en/api-reference.md‎

Lines changed: 202 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ The gateway accepts **either** an API key or a JWT. Console management endpoints
2525

2626
## Gateway Endpoints (port 3000)
2727

28+
The gateway serves three API formats on a single port, allowing clients to use whichever format they prefer:
29+
30+
| Endpoint | Format | Typical Clients |
31+
| --------------------------- | ----------------------- | -------------------------------------------- |
32+
| `POST /v1/chat/completions` | OpenAI Chat Completions | Cursor, Continue, Cline, OpenAI SDK |
33+
| `POST /v1/messages` | Anthropic Messages API | Claude Code, Anthropic SDK |
34+
| `POST /v1/responses` | OpenAI Responses API | OpenAI SDK (2025 format) |
35+
| `GET /v1/models` | OpenAI Models | All clients |
36+
37+
All three endpoints authenticate identically (API Key or JWT), route through the same model router and rate limiter, and produce the same usage records and audit logs.
38+
2839
### POST /v1/chat/completions
2940

3041
OpenAI-compatible chat completions endpoint. Proxies requests to the configured upstream provider.
@@ -187,6 +198,195 @@ curl http://localhost:3000/v1/models \
187198

188199
---
189200

201+
### POST /v1/messages
202+
203+
Anthropic Messages API endpoint. Accepts requests in the native Anthropic format and proxies them to the configured upstream provider. This allows Claude Code and the Anthropic SDK to connect directly without format translation on the client side.
204+
205+
**Authentication:** API Key or JWT
206+
207+
#### Request Body
208+
209+
```json
210+
{
211+
"model": "claude-sonnet-4-20250514",
212+
"max_tokens": 1024,
213+
"messages": [
214+
{
215+
"role": "user",
216+
"content": "Hello, Claude"
217+
}
218+
],
219+
"stream": false,
220+
"system": "You are a helpful assistant.",
221+
"temperature": 0.7
222+
}
223+
```
224+
225+
| Field | Type | Required | Default | Description |
226+
| ------------ | --------------- | -------- | ------- | ---------------------------------------- |
227+
| `model` | string | Yes | -- | Model identifier (e.g. `claude-sonnet-4-20250514`) |
228+
| `max_tokens` | integer | Yes | -- | Maximum tokens to generate |
229+
| `messages` | array\<object\> | Yes | -- | Conversation history |
230+
| `stream` | boolean | No | false | Enable Server-Sent Events streaming |
231+
| `system` | string | No | -- | System prompt |
232+
| `temperature`| number | No | 1.0 | Sampling temperature (0.0 -- 1.0) |
233+
234+
#### Response Body (non-streaming)
235+
236+
```json
237+
{
238+
"id": "msg_abc123",
239+
"type": "message",
240+
"role": "assistant",
241+
"content": [
242+
{
243+
"type": "text",
244+
"text": "Hello! How can I help you today?"
245+
}
246+
],
247+
"model": "claude-sonnet-4-20250514",
248+
"stop_reason": "end_turn",
249+
"usage": {
250+
"input_tokens": 12,
251+
"output_tokens": 10
252+
}
253+
}
254+
```
255+
256+
#### Response Body (streaming, `stream: true`)
257+
258+
The response is a stream of `text/event-stream` SSE events following the Anthropic streaming format:
259+
260+
```
261+
event: message_start
262+
data: {"type":"message_start","message":{"id":"msg_abc123","type":"message","role":"assistant","content":[],"model":"claude-sonnet-4-20250514"}}
263+
264+
event: content_block_delta
265+
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}
266+
267+
event: message_stop
268+
data: {"type":"message_stop"}
269+
```
270+
271+
#### Example
272+
273+
```bash
274+
curl -X POST http://localhost:3000/v1/messages \
275+
-H "Authorization: Bearer ab-your-api-key" \
276+
-H "Content-Type: application/json" \
277+
-H "anthropic-version: 2023-06-01" \
278+
-d '{
279+
"model": "claude-sonnet-4-20250514",
280+
"max_tokens": 1024,
281+
"messages": [{"role": "user", "content": "Hello"}]
282+
}'
283+
```
284+
285+
#### Error Responses
286+
287+
| Status | Condition |
288+
| ------ | -------------------------------- |
289+
| 401 | Missing/invalid credentials |
290+
| 403 | Model not allowed for this key |
291+
| 404 | Model not found |
292+
| 429 | Rate limit exceeded |
293+
| 502 | Upstream provider error |
294+
295+
---
296+
297+
### POST /v1/responses
298+
299+
OpenAI Responses API endpoint (2025 format). Accepts requests in the OpenAI Responses format, which supports both simple string inputs and structured message arrays.
300+
301+
**Authentication:** API Key or JWT
302+
303+
#### Request Body
304+
305+
```json
306+
{
307+
"model": "gpt-4o",
308+
"input": "What is the capital of France?",
309+
"instructions": "You are a helpful geography assistant.",
310+
"stream": false,
311+
"temperature": 0.7,
312+
"max_output_tokens": 4096
313+
}
314+
```
315+
316+
The `input` field can be either a simple string or an array of message objects:
317+
318+
```json
319+
{
320+
"model": "gpt-4o",
321+
"input": [
322+
{"role": "user", "content": "Hello"},
323+
{"role": "assistant", "content": "Hi there!"},
324+
{"role": "user", "content": "What is 2+2?"}
325+
]
326+
}
327+
```
328+
329+
| Field | Type | Required | Default | Description |
330+
| ------------------ | ----------------------- | -------- | ------- | ---------------------------------------- |
331+
| `model` | string | Yes | -- | Model identifier |
332+
| `input` | string or array\<object\> | Yes | -- | Prompt string or conversation messages |
333+
| `instructions` | string | No | -- | System-level instructions |
334+
| `stream` | boolean | No | false | Enable Server-Sent Events streaming |
335+
| `temperature` | number | No | 0.7 | Sampling temperature |
336+
| `max_output_tokens`| integer | No | -- | Maximum tokens to generate |
337+
338+
#### Response Body (non-streaming)
339+
340+
```json
341+
{
342+
"id": "resp_abc123",
343+
"object": "response",
344+
"created_at": 1711929600,
345+
"model": "gpt-4o",
346+
"output": [
347+
{
348+
"type": "message",
349+
"role": "assistant",
350+
"content": [
351+
{
352+
"type": "output_text",
353+
"text": "The capital of France is Paris."
354+
}
355+
]
356+
}
357+
],
358+
"usage": {
359+
"input_tokens": 15,
360+
"output_tokens": 8,
361+
"total_tokens": 23
362+
}
363+
}
364+
```
365+
366+
#### Example
367+
368+
```bash
369+
curl -X POST http://localhost:3000/v1/responses \
370+
-H "Authorization: Bearer ab-your-api-key" \
371+
-H "Content-Type: application/json" \
372+
-d '{
373+
"model": "gpt-4o",
374+
"input": "What is the capital of France?"
375+
}'
376+
```
377+
378+
#### Error Responses
379+
380+
| Status | Condition |
381+
| ------ | -------------------------------- |
382+
| 401 | Missing/invalid credentials |
383+
| 403 | Model not allowed for this key |
384+
| 404 | Model not found |
385+
| 429 | Rate limit exceeded |
386+
| 502 | Upstream provider error |
387+
388+
---
389+
190390
### POST /mcp
191391

192392
MCP (Model Context Protocol) Streamable HTTP transport endpoint. Accepts JSON-RPC 2.0 requests and routes them to registered MCP servers.
@@ -496,7 +696,7 @@ Perform initial system setup: create the first admin user and optionally configu
496696
| `provider` | object | No | Optional first provider configuration |
497697
| `provider.name` | string | Yes* | Unique slug identifier (* required if provider set) |
498698
| `provider.display_name` | string | Yes* | Human-readable name |
499-
| `provider.provider_type` | string | Yes* | One of `openai`, `anthropic`, `azure`, `custom` |
699+
| `provider.provider_type` | string | Yes* | One of `openai`, `anthropic`, `google`, `azure`, `bedrock`, `custom` |
500700
| `provider.base_url` | string | Yes* | Provider API base URL |
501701
| `provider.api_key` | string | Yes* | Provider API key |
502702

@@ -1177,7 +1377,7 @@ Register a new upstream AI provider.
11771377
| --------------- | ------ | -------- | ---------------------------------------------------- |
11781378
| `name` | string | Yes | Unique slug identifier (e.g. `openai-prod`) |
11791379
| `display_name` | string | Yes | Human-readable name |
1180-
| `provider_type` | string | Yes | One of `openai`, `anthropic`, `azure`, `custom` |
1380+
| `provider_type` | string | Yes | One of `openai`, `anthropic`, `google`, `azure`, `bedrock`, `custom` |
11811381
| `base_url` | string | Yes | Provider API base URL |
11821382
| `api_key` | string | Yes | Provider API key (encrypted at rest with AES-256-GCM)|
11831383

0 commit comments

Comments
 (0)