feat: enhance upstream endpoint handling with new passthrough header extraction and response management

- Introduced new types for endpoint preferences to support 'responses'.
- Added functions to extract safe passthrough headers, Claude-specific headers, and responses-specific headers.
- Implemented logic to ensure proper handling of stream accept headers.
- Updated endpoint resolution logic to prioritize 'responses' in certain contexts.
- Enhanced request building for 'messages' and 'responses' endpoints with improved body sanitization and header management.
- Added comprehensive documentation for new features and usage instructions.
This commit is contained in:
cita
2026-03-01 17:26:50 +08:00
parent af63df808d
commit 05a5ee9b9e
8 changed files with 2080 additions and 74 deletions
+47
View File
@@ -30,6 +30,11 @@
--><img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-5.x-3178C6?logo=typescript&style=flat">
</p>
<p align="center">
<a href="README.md"><strong>中文</strong></a> |
<a href="README_EN.md">English</a>
</p>
<p align="center">
<a href="docs/README.md"><strong>📚 文档中心</strong></a> ·
<a href="docs/getting-started.md">快速上手</a> ·
@@ -399,6 +404,47 @@ Metapi 对下游暴露标准 OpenAI / Claude 兼容接口:
| **API Key** | 你设置的 `PROXY_TOKEN` 值 |
| **模型列表** | 自动从 `GET /v1/models` 获取 |
### CLI 快速配置(Claude Code / Codex)
#### Claude Code(`~/.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"
}
}
```
> 说明:不同版本客户端可能读取 `ANTHROPIC_API_KEY` 或 `ANTHROPIC_AUTH_TOKEN`,建议同时设置。
#### Codex(`~/.codex/config.toml` + `~/.codex/auth.json`)
`~/.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` 可见的模型名。
### 已验证兼容的客户端
- [ChatGPT-Next-Web](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web)
@@ -406,6 +452,7 @@ Metapi 对下游暴露标准 OpenAI / Claude 兼容接口:
- [Cherry Studio](https://github.com/kangfenmao/cherry-studio)
- [Cursor](https://cursor.sh)
- [Claude Code](https://docs.anthropic.com/en/docs/claude-code)
- Codex CLI
- [Roo Code](https://github.com/RooVetGit/Roo-Code)
- [Kilo Code](https://github.com/kilocode/kilocode)
- 以及所有支持 OpenAI API 格式的客户端