Skip to content

Commit 4c14fe6

Browse files
committed
feat: add Claude Code (OAuth) mode as independent provider
- Add configureClaudeCodeProvider() function in get-ai-gateway.sh - Add Claude Code to Top 10 commonly used providers list - Support --claude-code-key and --claude-code-models CLI flags - Add CLAUDE_CODE_MODELS default pattern: claude-code-* - Add claudeCodeMode=true configuration in ai-gateway.sh - Claude Code uses OAuth token (Bearer auth) instead of x-api-key - Enables Claude Code CLI token authentication for AI Gateway Claude Code mode differences: - Uses Bearer token authorization - Sets x-app: cli header - Adds anthropic-beta headers for OAuth/Claude Code features - Adds ?beta=true query parameter - Auto-injects default system prompt and Bash tool
1 parent f6588f3 commit 4c14fe6

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

all-in-one/get-ai-gateway.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ parseArgs() {
244244
LLM_ENVS+=("CLAUDE_VERSION")
245245
shift 2
246246
;;
247+
--claude-code-key)
248+
CLAUDE_CODE_API_KEY="$2"
249+
LLM_ENVS+=("CLAUDE_CODE_API_KEY")
250+
shift 2
251+
;;
247252
--gemini-key)
248253
GEMINI_API_KEY="$2"
249254
LLM_ENVS+=("GEMINI_API_KEY")
@@ -435,6 +440,11 @@ parseArgs() {
435440
LLM_ENVS+=("CLAUDE_MODELS")
436441
shift 2
437442
;;
443+
--claude-code-models)
444+
CLAUDE_CODE_MODELS="$2"
445+
LLM_ENVS+=("CLAUDE_CODE_MODELS")
446+
shift 2
447+
;;
438448
--cohere-models)
439449
COHERE_MODELS="$2"
440450
LLM_ENVS+=("COHERE_MODELS")
@@ -597,6 +607,7 @@ resetEnv() {
597607
: "${BAICHUAN_MODELS:=Baichuan*}"
598608
: "${BAIDU_MODELS:=ERNIE-*}"
599609
: "${CLAUDE_MODELS:=claude-*}"
610+
: "${CLAUDE_CODE_MODELS:=claude-code-*}"
600611
: "${CLOUDFLARE_MODELS:=*}"
601612
: "${COHERE_MODELS:=command*}"
602613
: "${DEEPL_MODELS:=*}"
@@ -690,10 +701,11 @@ runConfigWizard() {
690701
"DeepSeek|DEEPSEEK|configureDeepSeekProvider"
691702
"Moonshot (Kimi)|MOONSHOT|configureMoonshotProvider"
692703
"Zhipu AI|ZHIPUAI|configureZhipuAIProvider"
704+
"Claude Code|CLAUDE_CODE|configureClaudeCodeProvider"
705+
"Claude|CLAUDE|configureClaudeProvider"
693706
"Minimax|MINIMAX|configureMinimaxProvider"
694707
"Azure OpenAI|AZURE|configureAzureProvider"
695708
"AWS Bedrock|BEDROCK|configureBedrockProvider"
696-
"Google Vertex AI|VERTEX|configureVertexProvider"
697709
"OpenAI|OPENAI|configureOpenAIProvider"
698710
"OpenRouter|OPENROUTER|configureOpenRouterProvider"
699711
# Other providers (alphabetically ordered)
@@ -834,6 +846,21 @@ configureClaudeProvider() {
834846
LLM_ENVS+=("CLAUDE_MODELS")
835847
}
836848

849+
configureClaudeCodeProvider() {
850+
read -r -u 3 -p "→ Enter OAuth Token for Claude Code: " CLAUDE_CODE_API_KEY
851+
LLM_ENVS+=("CLAUDE_CODE_API_KEY")
852+
853+
# Configure model pattern
854+
if [ -z "$CLAUDE_CODE_MODELS" ]; then
855+
echo "Enter model pattern for routing (prefix match, e.g., 'claude-code-'):"
856+
read -r -u 3 -p "→ Model pattern (default: claude-code-*): " CLAUDE_CODE_MODELS
857+
if [ -z "$CLAUDE_CODE_MODELS" ]; then
858+
CLAUDE_CODE_MODELS="claude-code-*"
859+
fi
860+
fi
861+
LLM_ENVS+=("CLAUDE_CODE_MODELS")
862+
}
863+
837864
configureMinimaxProvider() {
838865
read -r -u 3 -p "→ Enter API Key for Minimax: " MINIMAX_API_KEY
839866
read -r -u 3 -p "→ Enter group ID for Minimax (only required when using ChatCompletion Pro): " MINIMAX_GROUP_ID
@@ -1390,7 +1417,7 @@ ${env}=${!env}"
13901417
for model_env in DASHSCOPE_MODELS DEEPSEEK_MODELS MOONSHOT_MODELS ZHIPUAI_MODELS \
13911418
MINIMAX_MODELS AZURE_MODELS BEDROCK_MODELS VERTEX_MODELS \
13921419
OPENAI_MODELS OPENROUTER_MODELS YI_MODELS AI360_MODELS \
1393-
BAICHUAN_MODELS BAIDU_MODELS CLAUDE_MODELS CLOUDFLARE_MODELS \
1420+
BAICHUAN_MODELS BAIDU_MODELS CLAUDE_MODELS CLAUDE_CODE_MODELS CLOUDFLARE_MODELS \
13941421
COHERE_MODELS DEEPL_MODELS DIFY_MODELS DOUBAO_MODELS \
13951422
FIREWORKS_MODELS GITHUB_MODELS GEMINI_MODELS GROK_MODELS \
13961423
GROQ_MODELS MISTRAL_MODELS OLLAMA_MODELS SPARK_MODELS \
@@ -1479,6 +1506,7 @@ LLM Provider API Keys:
14791506
--openrouter-key KEY OpenRouter API key
14801507
--claude-key KEY Claude API key
14811508
--claude-version VER Claude API version (default: 2023-06-01)
1509+
--claude-code-key KEY Claude Code OAuth token
14821510
--gemini-key KEY Google Gemini API key
14831511
--groq-key KEY Groq API key
14841512
--doubao-key KEY Doubao API key
@@ -1536,6 +1564,7 @@ Model Pattern Configurations:
15361564
--baichuan-models PATTERN Model pattern for Baichuan AI
15371565
--baidu-models PATTERN Model pattern for Baidu AI Cloud
15381566
--claude-models PATTERN Model pattern for Claude
1567+
--claude-code-models PATTERN Model pattern for Claude Code (OAuth)
15391568
--cloudflare-models PATTERN Model pattern for Cloudflare Workers AI
15401569
--cohere-models PATTERN Model pattern for Cohere
15411570
--deepl-models PATTERN Model pattern for DeepL

all-in-one/scripts/config-template/ai-gateway.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ function initializeLlmProviderConfigs() {
190190
IFS='|' read -r CLAUDE_TYPE CLAUDE_PATTERN <<< "$(normalizeModelPattern "$CLAUDE_MODELS")"
191191
initializeLlmProviderConfig claude claude CLAUDE api.anthropic.com "443" "https" "" "$CLAUDE_TYPE" "$CLAUDE_PATTERN" "${EXTRA_CONFIGS[@]}"
192192

193+
# Claude Code (OAuth mode)
194+
if [ -n "$CLAUDE_CODE_API_KEY" ]; then
195+
EXTRA_CONFIGS=(
196+
"claudeCodeMode=true"
197+
)
198+
local CLAUDE_CODE_MODELS="${CLAUDE_CODE_MODELS}"
199+
IFS='|' read -r CLAUDE_CODE_TYPE CLAUDE_CODE_PATTERN <<< "$(normalizeModelPattern "$CLAUDE_CODE_MODELS")"
200+
initializeLlmProviderConfig claude-code claude-code CLAUDE_CODE api.anthropic.com "443" "https" "" "$CLAUDE_CODE_TYPE" "$CLAUDE_CODE_PATTERN" "${EXTRA_CONFIGS[@]}"
201+
fi
202+
193203
# Cloudflare Workers AI
194204
if [ -n "$CLOUDFLARE_CONFIGURED" ]; then
195205
EXTRA_CONFIGS=()

0 commit comments

Comments
 (0)