Add custom headers support for models.json

Fixes #39

- Added headers field to Model type (provider and model level)
- Model headers override provider headers when merged
- Supported in all APIs:
  - Anthropic: defaultHeaders
  - OpenAI (completions/responses): defaultHeaders
  - Google: httpOptions.headers
- Enables bypassing Cloudflare bot detection for proxied endpoints
- Updated documentation with examples

Also fixed:
- Mistral/Chutes syntax error (iif -> if)
- process.env.ANTHROPIC_API_KEY bug (use delete instead of = undefined)
This commit is contained in:
Mario Zechner 2025-11-20 17:05:31 +01:00
parent 425890e674
commit de39f1f493
9 changed files with 95 additions and 7 deletions

View file

@ -288,11 +288,12 @@ function createClient(
accept: "application/json",
"anthropic-dangerous-direct-browser-access": "true",
"anthropic-beta": "oauth-2025-04-20,fine-grained-tool-streaming-2025-05-14",
...(model.headers || {}),
};
// Clear the env var if we're in Node.js to prevent SDK from using it
if (typeof process !== "undefined" && process.env) {
process.env.ANTHROPIC_API_KEY = undefined;
delete process.env.ANTHROPIC_API_KEY;
}
const client = new Anthropic({
@ -309,6 +310,7 @@ function createClient(
accept: "application/json",
"anthropic-dangerous-direct-browser-access": "true",
"anthropic-beta": "fine-grained-tool-streaming-2025-05-14",
...(model.headers || {}),
};
const client = new Anthropic({