Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions app/lib/modules/llm/providers/anthropic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, it, vi } from 'vitest';

vi.mock('@ai-sdk/anthropic', () => ({
createAnthropic: vi.fn().mockReturnValue(vi.fn().mockReturnValue({ id: 'mock-model' })),
}));

vi.mock('~/lib/modules/llm/manager', () => ({
LLMManager: {
getInstance: vi.fn().mockReturnValue({ env: {} }),
},
}));

import AnthropicProvider from './anthropic';
import { createAnthropic } from '@ai-sdk/anthropic';

describe('AnthropicProvider', () => {
it('passes User-Agent header when creating Anthropic client', () => {
const provider = new AnthropicProvider();
provider.getModelInstance({
model: 'claude-3-5-sonnet-20241022',
serverEnv: {} as any,
apiKeys: { ANTHROPIC_API_KEY: 'test-key' },
providerSettings: {},
});

expect(createAnthropic).toHaveBeenCalledWith(
expect.objectContaining({
headers: expect.objectContaining({
'User-Agent': expect.stringMatching(/^bolt\.diy\//),
}),
}),
);
});
});
5 changes: 4 additions & 1 deletion app/lib/modules/llm/providers/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export default class AnthropicProvider extends BaseProvider {
});
const anthropic = createAnthropic({
apiKey,
headers: { 'anthropic-beta': 'output-128k-2025-02-19' },
headers: {
'anthropic-beta': 'output-128k-2025-02-19',
'User-Agent': 'bolt.diy/1.0.0',
},
});

return anthropic(model);
Expand Down
Loading