forked from boos/BoosAPI
feat(tests): add comprehensive tests for TokenRouter and related components
- Implement tests for TokenRouter downstream policy, covering allowedRouteIds and site weight multipliers. - Add tests for TokenRouter patterns and model mapping, including regex pattern matching and model mapping precedence. - Create tests for BrandIcon component to verify brand detection logic. - Develop tests for Accounts page, focusing on rebind panel behavior and refresh action on error. - Introduce fuzzy search utility tests to validate substring and subsequence matching. - Implement navigation focus helpers tests for building and parsing focus paths. - Add progressive render tests to ensure correct initial and next visible counts. - Create route model candidates index tests to validate route candidate indexing and matching logic.
This commit is contained in:
+55
-11
@@ -13,7 +13,7 @@ Metapi 暴露标准 OpenAI / Claude 兼容接口,下游客户端只需配置
|
||||
| 配置项 | 值 |
|
||||
|--------|-----|
|
||||
| **Base URL** | `https://your-domain.com`(不要拼接 `/v1`,客户端会自动加) |
|
||||
| **API Key** | 你设置的 `PROXY_TOKEN` 值 |
|
||||
| **API Key** | 你设置的 `PROXY_TOKEN` 值,或创建的下游 API Key |
|
||||
|
||||
模型列表自动从 `GET /v1/models` 获取,无需手动配置。
|
||||
|
||||
@@ -61,19 +61,46 @@ Metapi 暴露标准 OpenAI / Claude 兼容接口,下游客户端只需配置
|
||||
|
||||
### Claude Code
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_BASE_URL=https://your-domain.com
|
||||
export ANTHROPIC_API_KEY=your-proxy-sk-token
|
||||
export CLAUDE_CODE_ATTRIBUTION_HEADER=0
|
||||
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
|
||||
# 可选:进一步关闭非必要模型调用
|
||||
export DISABLE_NON_ESSENTIAL_MODEL_CALLS=1
|
||||
在 `~/.claude/settings.json` 中配置:
|
||||
|
||||
```json
|
||||
{
|
||||
“env”: {
|
||||
“ANTHROPIC_BASE_URL”: “https://your-domain.com”,
|
||||
“ANTHROPIC_API_KEY”: “your-proxy-sk-token”,
|
||||
“ANTHROPIC_AUTH_TOKEN”: “your-proxy-sk-token”,
|
||||
“CLAUDE_CODE_ATTRIBUTION_HEADER”: “0”,
|
||||
“CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC”: “1”
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
或在配置文件中设置相应的环境变量(例如 `~/.claude/settings.json`)。
|
||||
> 说明:不同版本客户端可能读取 `ANTHROPIC_API_KEY` 或 `ANTHROPIC_AUTH_TOKEN`,建议同时设置。
|
||||
> 上述变量由 Claude Code 客户端读取,属于客户端行为开关;
|
||||
> `metapi` 服务端无法替代客户端”设置这些变量”,只能处理已经发来的请求。
|
||||
|
||||
> 说明:上述变量由 Claude Code 客户端读取,属于客户端行为开关;
|
||||
> `metapi` 服务端无法替代客户端“设置这些变量”,只能处理已经发来的请求。
|
||||
### Codex CLI
|
||||
|
||||
`~/.codex/config.toml`
|
||||
|
||||
```toml
|
||||
model = “gpt-5”
|
||||
model_provider = “metapi”
|
||||
|
||||
[model_providers.metapi]
|
||||
name = “metapi”
|
||||
base_url = “https://your-domain.com/v1”
|
||||
```
|
||||
|
||||
`~/.codex/auth.json`
|
||||
|
||||
```json
|
||||
{
|
||||
“OPENAI_API_KEY”: “your-proxy-sk-token”
|
||||
}
|
||||
```
|
||||
|
||||
> 提示:`model` 需要是你在 Metapi `GET /v1/models` 可见的模型名。
|
||||
|
||||
### Roo Code / Kilo Code
|
||||
|
||||
@@ -83,6 +110,23 @@ export DISABLE_NON_ESSENTIAL_MODEL_CALLS=1
|
||||
|
||||
所有支持 OpenAI API 格式的客户端均可接入,只需找到 Base URL 和 API Key 的配置位置即可。
|
||||
|
||||
## 下游 API Key 策略
|
||||
|
||||
除了全局 `PROXY_TOKEN`,你还可以在 **系统设置 → 下游 API Key 策略** 中创建多个项目级下游 Key,每个 Key 可独立配置:
|
||||
|
||||
| 配置项 | 说明 |
|
||||
|--------|------|
|
||||
| **过期时间**(ExpiresAt) | Key 到期后自动失效 |
|
||||
| **费用上限**(MaxCost) | 累计消费超限后拒绝请求 |
|
||||
| **请求上限**(MaxRequests) | 累计请求数超限后拒绝请求 |
|
||||
| **模型白名单**(SupportedModels) | 限制可用模型,支持 exact / glob / `re:regex` |
|
||||
| **路由白名单**(AllowedRouteIds) | 限制可走的路由规则 |
|
||||
| **站点倍率**(SiteWeightMultipliers) | 按站点调整路由权重,控制上游偏好 |
|
||||
|
||||
适用于多团队/多项目共用一个 Metapi 实例但需要独立计量和权限控制的场景。
|
||||
|
||||
---
|
||||
|
||||
## 快速自检
|
||||
|
||||
部署完成后,用以下命令验证链路:
|
||||
|
||||
Reference in New Issue
Block a user