Fix Azure Claude to use Anthropic API format (x-api-key, /v1/messages)
This commit is contained in:
parent
7a7d455414
commit
7bb7f8883c
1 changed files with 11 additions and 18 deletions
|
|
@ -93,11 +93,8 @@ impl ClaudeClient {
|
||||||
|
|
||||||
fn build_url(&self) -> String {
|
fn build_url(&self) -> String {
|
||||||
if self.is_azure {
|
if self.is_azure {
|
||||||
format!(
|
// Azure Claude exposes Anthropic API directly at /v1/messages
|
||||||
"{}/deployments/{}/messages?api-version=2024-06-01",
|
format!("{}/v1/messages", self.base_url.trim_end_matches('/'))
|
||||||
self.base_url.trim_end_matches('/'),
|
|
||||||
self.deployment_name
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
format!("{}/v1/messages", self.base_url.trim_end_matches('/'))
|
format!("{}/v1/messages", self.base_url.trim_end_matches('/'))
|
||||||
}
|
}
|
||||||
|
|
@ -106,17 +103,13 @@ impl ClaudeClient {
|
||||||
fn build_headers(&self, api_key: &str) -> reqwest::header::HeaderMap {
|
fn build_headers(&self, api_key: &str) -> reqwest::header::HeaderMap {
|
||||||
let mut headers = reqwest::header::HeaderMap::new();
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
|
|
||||||
if self.is_azure {
|
// Both Azure Claude and direct Anthropic use the same headers
|
||||||
if let Ok(val) = api_key.parse() {
|
// Azure Claude proxies the Anthropic API format
|
||||||
headers.insert("api-key", val);
|
if let Ok(val) = api_key.parse() {
|
||||||
}
|
headers.insert("x-api-key", val);
|
||||||
} else {
|
}
|
||||||
if let Ok(val) = api_key.parse() {
|
if let Ok(val) = "2023-06-01".parse() {
|
||||||
headers.insert("x-api-key", val);
|
headers.insert("anthropic-version", val);
|
||||||
}
|
|
||||||
if let Ok(val) = "2023-06-01".parse() {
|
|
||||||
headers.insert("anthropic-version", val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(val) = "application/json".parse() {
|
if let Ok(val) = "application/json".parse() {
|
||||||
|
|
@ -432,8 +425,8 @@ mod tests {
|
||||||
"claude-opus-4-5".to_string(),
|
"claude-opus-4-5".to_string(),
|
||||||
);
|
);
|
||||||
let url = client.build_url();
|
let url = client.build_url();
|
||||||
assert!(url.contains("deployments/claude-opus-4-5/messages"));
|
// Azure Claude uses Anthropic API format directly
|
||||||
assert!(url.contains("api-version="));
|
assert!(url.contains("/v1/messages"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue