v2.2.0: API Key鉴权(可配置) + Function Calling透传 + MCP Server标准接口
- API Key鉴权: /v1/* 与 /mcp 接口支持 Bearer 鉴权(OpenAI兼容), 系统配置页可启停/增删Key (GET/PUT /api/admin/apikeys, key脱敏显示; /health /status 不受限; 内部自调用自动带key) - Function Calling: tools/tool_calls 全透传上游, 实测 GLM-5.3-flash 返回 tool_calls(get_weather) - MCP Server: /mcp 端点(Streamable HTTP + SSE兼容), 暴露 text_complete/vision_complete/image_generate 工具 (initialize/ping/tools/list/tools/call/prompts.list/resources.list; 实测生图返回图片URL) - 默认生成 API Key: sk-hz4th-<hex>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
> 兼容OpenAI API格式的多提供商代理系统,支持能力(Capability)路由、优先级自动切换
|
||||
|
||||
**版本:v2.1.2**
|
||||
**版本:v2.2.0**
|
||||
|
||||
## 功能特点
|
||||
|
||||
@@ -212,6 +212,43 @@ MODEL_ALIASES = {
|
||||
- **端点**:`/api/admin/email`(GET/PUT)、`/api/admin/email/test`(POST)
|
||||
- **默认配置**:`mail.tphai.com:587`(plain)、收件人 `wlq@tphai.com`
|
||||
|
||||
## 接口认证(API Key)
|
||||
|
||||
为 `/v1/*` 与 `/mcp` 接口启用 Bearer 鉴权(OpenAI 兼容):
|
||||
|
||||
```bash
|
||||
curl http://<IP>:16003/v1/chat/completions \
|
||||
-H "Authorization: Bearer sk-hz4th-xxxx" \
|
||||
...
|
||||
```
|
||||
|
||||
- **配置入口**:后台「系统配置」页 → 接口认证(API Key),可启停鉴权、增删多个 Key
|
||||
- **管理接口**:`/api/admin/apikeys`(GET/PUT)
|
||||
- `/health`、`/status` 不受鉴权影响
|
||||
|
||||
## 标准接口
|
||||
|
||||
| 接口 | 说明 |
|
||||
|------|------|
|
||||
| OpenAI 兼容 | `/v1/chat/completions` 等,支持流式、`tools`/function calling 透传 |
|
||||
| Function Calling | 请求体带 `tools` 数组即透传上游,返回 `tool_calls`(实测 GLM/DeepSeek 正常) |
|
||||
| MCP Server | 连接 `http://<IP>:16003/mcp`(Streamable HTTP + SSE),工具:`text_complete` / `vision_complete` / `image_generate` |
|
||||
|
||||
### MCP 使用示例
|
||||
|
||||
```bash
|
||||
curl http://<IP>:16003/mcp \
|
||||
-H "Authorization: Bearer sk-hz4th-xxxx" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}'
|
||||
|
||||
# 调用文本模型
|
||||
curl http://<IP>:16003/mcp -H "Authorization: Bearer sk-hz4th-xxxx" -H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"text_complete","arguments":{"model":"auto-text","prompt":"你好"}}}'
|
||||
```
|
||||
|
||||
Claude Desktop / Cursor 等支持 MCP 的客户端可直接将 `http://<IP>:16003/mcp` 配为 MCP Server。
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user