Skip to content

Commit 160b758

Browse files
authored
feat(model-provider): add automatic claude headers support (#1314)
1 parent dfd3ad3 commit 160b758

21 files changed

Lines changed: 351 additions & 4 deletions

multimodal/tarko/agent/tests/agent/kernel/agent.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ describe('Agent', () => {
151151
"baseProvider": "openai",
152152
"baseURL": undefined,
153153
"displayName": undefined,
154+
"headers": {},
154155
"id": "gpt-4o",
156+
"params": undefined,
155157
"provider": "openai",
156158
}
157159
`);

multimodal/tarko/llm-client/src/handlers/anthropic.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,10 @@ export class AnthropicHandler extends BaseHandler<AnthropicModel> {
543543

544544
const stream = typeof body.stream === 'boolean' ? body.stream : undefined;
545545
const maxTokens = body.max_tokens ?? getDefaultMaxTokens(body.model);
546-
const client = new Anthropic({ apiKey: getApiKey(this.opts.apiKey)! });
546+
const client = new Anthropic({
547+
apiKey: getApiKey(this.opts.apiKey)!,
548+
defaultHeaders: this.opts.defaultHeaders,
549+
});
547550
const stopSequences = convertStopSequences(body.stop);
548551
const topP = typeof body.top_p === 'number' ? body.top_p : undefined;
549552
const temperature =

multimodal/tarko/llm-client/src/handlers/azure-openai.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class AzureOpenAIHandler extends BaseHandler<AzureOpenAIModel> {
4747
azureADTokenProvider,
4848
apiVersion,
4949
endpoint,
50+
defaultHeaders: this.opts.defaultHeaders,
5051
});
5152

5253
// We have to delete the provider field because it's not a valid parameter for the OpenAI API.

multimodal/tarko/llm-client/src/handlers/groq.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class GroqHandler extends BaseHandler<GroqModel> {
4444
const client = new OpenAI({
4545
apiKey,
4646
baseURL: 'https://api.groq.com/openai/v1',
47+
defaultHeaders: this.opts.defaultHeaders,
4748
});
4849

4950
if (apiKey === undefined) {

multimodal/tarko/llm-client/src/handlers/openai-compatible.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export class OpenAICompatibleHandler extends BaseHandler<OpenAICompatibleModel>
7676
const openai = new OpenAI({
7777
...this.opts,
7878
apiKey,
79+
defaultHeaders: this.opts.defaultHeaders,
7980
});
8081

8182
// We have to delete the provider field because it's not a valid parameter for the OpenAI API.

multimodal/tarko/llm-client/src/handlers/openai-non-streaming.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export class OpenAINonStreamingHandler extends BaseHandler<OpenAIModel> {
116116
const openai = new OpenAI({
117117
...this.opts,
118118
apiKey,
119+
defaultHeaders: this.opts.defaultHeaders,
119120
});
120121

121122
// We have to delete the provider field because it's not a valid parameter for the OpenAI API

multimodal/tarko/llm-client/src/handlers/openai.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class OpenAIHandler extends BaseHandler<OpenAIModel> {
3737
const openai = new OpenAI({
3838
...this.opts,
3939
apiKey,
40+
defaultHeaders: this.opts.defaultHeaders,
4041
});
4142

4243
// We have to delete the provider field because it's not a valid parameter for the OpenAI API.

multimodal/tarko/llm-client/src/handlers/openrouter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class OpenRouterHandler extends BaseHandler<OpenRouterModel> {
3535
defaultHeaders: {
3636
'HTTP-Referer': 'docs.tokenjs.ai',
3737
'X-Title': 'Token.js',
38+
...this.opts.defaultHeaders,
3839
},
3940
});
4041

multimodal/tarko/llm-client/src/handlers/perplexity.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class PerplexityHandler extends BaseHandler<PerplexityModel> {
4242
...this.opts,
4343
baseURL: 'https://api.perplexity.ai',
4444
apiKey,
45+
defaultHeaders: this.opts.defaultHeaders,
4546
});
4647

4748
const model = body.model.replace(PERPLEXITY_PREFIX, '');

multimodal/tarko/llm-client/src/userTypes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from 'openai/resources/index';
2222

2323
export type ConfigOptions = Pick<ClientOptions, 'apiKey' | 'baseURL'> & {
24+
defaultHeaders?: Record<string, string>;
2425
azure?: {
2526
endpoint?: string;
2627
apiVersion?: string;

0 commit comments

Comments
 (0)