Skip to content

Commit d6e58fd

Browse files
committed
fixx
1 parent 06f5814 commit d6e58fd

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

crates/braintrust-llm-router/src/providers/azure_ai_gateway.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl AzureAiGatewayProvider {
110110
}
111111
let status = response.status();
112112
let headers = response.headers().clone();
113-
let text = response.text().await.unwrap_or_default();
113+
let text = response.text().await?;
114114
Err(Error::Provider {
115115
provider: "azure_ai_gateway".to_string(),
116116
source: anyhow::anyhow!("HTTP {status}: {text}"),
@@ -164,7 +164,7 @@ impl Provider for AzureAiGatewayProvider {
164164
}
165165
let status = response.status();
166166
let headers = response.headers().clone();
167-
let text = response.text().await.unwrap_or_default();
167+
let text = response.text().await?;
168168
Err(Error::Provider {
169169
provider: "azure_ai_gateway".to_string(),
170170
source: anyhow::anyhow!("HTTP {status}: {text}"),

crates/braintrust-llm-router/src/router.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -873,11 +873,14 @@ impl Router {
873873
&& spec.requires_responses_api()
874874
{
875875
ProviderFormat::Responses
876-
} else if matches!(provider.id(), "azure" | "azure_ai_gateway")
877-
&& catalog_format == ProviderFormat::Anthropic
878-
{
879-
// Anthropic on Azure and Azure AI Gateway only supports the messages
880-
// format and isn’t interchangeable with other APIs.
876+
} else if provider.id() == "azure_ai_gateway" {
877+
// Azure AI Gateway has distinct endpoints for each provider format.
878+
// Preserve the catalog transport rather than selecting a route from
879+
// the caller's requested output format.
880+
catalog_format
881+
} else if provider.id() == "azure" && catalog_format == ProviderFormat::Anthropic {
882+
// Anthropic on Azure only supports the messages format and isn’t
883+
// interchangeable with other APIs.
881884
ProviderFormat::Anthropic
882885
} else if provider.id() == "anthropic" {
883886
// Native Anthropic has two endpoints: /v1/messages (Anthropic format) and the
@@ -2707,6 +2710,37 @@ mod tests {
27072710
assert_eq!(format, ProviderFormat::ChatCompletions);
27082711
}
27092712

2713+
#[test]
2714+
fn azure_ai_gateway_preserves_chat_completions_transport_for_anthropic_output() {
2715+
let model = "gpt-5-mini";
2716+
let mut catalog = ModelCatalog::empty();
2717+
catalog.insert(model.into(), openai_spec(model, ModelFlavor::Chat));
2718+
let router = Router::builder()
2719+
.with_catalog(Arc::new(catalog))
2720+
.add_provider(
2721+
"azure_ai_gateway",
2722+
FakeProvider {
2723+
name: "azure_ai_gateway",
2724+
formats: vec![
2725+
ProviderFormat::ChatCompletions,
2726+
ProviderFormat::Responses,
2727+
ProviderFormat::Anthropic,
2728+
],
2729+
},
2730+
dummy_auth(),
2731+
vec![ProviderFormat::ChatCompletions],
2732+
)
2733+
.build()
2734+
.expect("router builds");
2735+
2736+
let routes = router
2737+
.resolve_provider_routes(model, ProviderFormat::Anthropic, &[])
2738+
.expect("resolves");
2739+
2740+
assert_eq!(routes.len(), 1);
2741+
assert_eq!(routes[0].format, ProviderFormat::ChatCompletions);
2742+
}
2743+
27102744
#[test]
27112745
fn bedrock_converse_catalog_format_keeps_converse_transport_for_chat_output() {
27122746
let bedrock_spec = |model: &str, format: ProviderFormat| ModelSpec {

0 commit comments

Comments
 (0)