Skip to content
Closed
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
20 changes: 17 additions & 3 deletions src/llm/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,27 @@ impl SpacebotModel {
body["tools"] = serde_json::json!(tools);
}

let response = self
// Detect OAuth setup-tokens (sk-ant-oat...) vs regular API keys.
// OAuth tokens require Bearer auth + Claude Code beta headers instead of x-api-key.
let is_oauth = api_key.contains("sk-ant-oat");
let claude_code_version = "0.2.116";
let mut req = self
.llm_manager
.http_client()
.post("https://api.anthropic.com/v1/messages")
.header("x-api-key", &api_key)
.header("anthropic-version", "2023-06-01")
.header("content-type", "application/json")
.header("content-type", "application/json");
if is_oauth {
req = req
.header("Authorization", format!("Bearer {}", &api_key))
.header("anthropic-beta", "claude-code-20250219,oauth-2025-04-20")
.header("anthropic-dangerous-direct-browser-access", "true")
.header("user-agent", format!("claude-cli/{} (external, cli)", claude_code_version))
.header("x-app", "cli");
} else {
req = req.header("x-api-key", &api_key);
}
let response = req
.json(&body)
.send()
.await
Expand Down