mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 00:04:49 +00:00
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:
parent
425890e674
commit
de39f1f493
9 changed files with 95 additions and 7 deletions
|
|
@ -63,7 +63,7 @@ export const streamGoogle: StreamFunction<"google-generative-ai"> = (
|
|||
};
|
||||
|
||||
try {
|
||||
const client = createClient(options?.apiKey);
|
||||
const client = createClient(model, options?.apiKey);
|
||||
const params = buildParams(model, context, options);
|
||||
const googleStream = await client.models.generateContentStream(params);
|
||||
|
||||
|
|
@ -252,7 +252,7 @@ export const streamGoogle: StreamFunction<"google-generative-ai"> = (
|
|||
return stream;
|
||||
};
|
||||
|
||||
function createClient(apiKey?: string): GoogleGenAI {
|
||||
function createClient(model: Model<"google-generative-ai">, apiKey?: string): GoogleGenAI {
|
||||
if (!apiKey) {
|
||||
if (!process.env.GEMINI_API_KEY) {
|
||||
throw new Error(
|
||||
|
|
@ -261,7 +261,10 @@ function createClient(apiKey?: string): GoogleGenAI {
|
|||
}
|
||||
apiKey = process.env.GEMINI_API_KEY;
|
||||
}
|
||||
return new GoogleGenAI({ apiKey });
|
||||
return new GoogleGenAI({
|
||||
apiKey,
|
||||
httpOptions: model.headers ? { headers: model.headers } : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
function buildParams(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue