Skip to content

Commit 78f036e

Browse files
committed
Add support for multiple Anthropic API keys
This change introduces the ability to use a secondary Anthropic API key (ANTHROPIC_API_KEY2) in addition to the primary one. The system now randomly selects between the two keys when making API calls, which can help distribute load and potentially avoid rate limiting issues. The env.mjs file has been updated to include the new ANTHROPIC_API_KEY2 environment variable, ensuring proper validation and type checking.
1 parent 7397c06 commit 78f036e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

backend/src/claude.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export const promptClaudeStream = async function* (
3838
ignoreHelicone = false,
3939
} = options
4040

41-
const apiKey = env.ANTHROPIC_API_KEY
41+
const apiKey =
42+
Math.random() > 0.5 ? env.ANTHROPIC_API_KEY : env.ANTHROPIC_API_KEY2
4243

4344
if (!apiKey) {
4445
throw new Error('Missing ANTHROPIC_API_KEY')

backend/src/env.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dotenv.config({ path })
1616
export const env = createEnv({
1717
server: {
1818
ANTHROPIC_API_KEY: z.string().min(1).startsWith('sk-ant-'),
19+
ANTHROPIC_API_KEY2: z.string().min(1).startsWith('sk-ant-'),
1920
HELICONE_API_KEY: z.string().min(1).startsWith('pk-helicone-'),
2021
OPEN_AI_KEY: z.string().min(1).startsWith('sk-proj-'),
2122
STRIPE_SECRET_KEY: z.string().min(1),

0 commit comments

Comments
 (0)