use crate::providers::{
anthropic::ANTHROPIC_VERSION, claude_code::auth::ClaudeCodeAccessMode,
openai::package_user_agent,
};
use std::collections::BTreeMap;
const BASE_BETAS: &str = "interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14";
const OAUTH_BETAS: &str = "interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14,claude-code-20250219,oauth-2025-04-20";
pub(crate) fn claude_code_headers(auth: ClaudeCodeAccessMode<'_>) -> BTreeMap<String, String> {
let mut headers = BTreeMap::from([
("accept".to_string(), "text/event-stream".to_string()),
(
"anthropic-version".to_string(),
ANTHROPIC_VERSION.to_string(),
),
("content-type".to_string(), "application/json".to_string()),
]);
match auth {
ClaudeCodeAccessMode::ApiKey(key) => {
headers.insert("anthropic-beta".to_string(), BASE_BETAS.to_string());
headers.insert("user-agent".to_string(), package_user_agent());
headers.insert("x-api-key".to_string(), key.to_string());
}
ClaudeCodeAccessMode::OAuth(token) => {
headers.insert("anthropic-beta".to_string(), OAUTH_BETAS.to_string());
headers.insert("authorization".to_string(), format!("Bearer {token}"));
headers.insert(
"user-agent".to_string(),
format!("claude-cli/{} (external, cli)", env!("CARGO_PKG_VERSION")),
);
headers.insert("x-app".to_string(), "cli".to_string());
}
}
headers
}