Skip to content
Merged
Show file tree
Hide file tree
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
50 changes: 12 additions & 38 deletions crates/braintrust-llm-router/src/providers/anthropic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,35 +124,23 @@ impl crate::providers::Provider for AnthropicProvider {
) -> Result<Bytes> {
let url = self.messages_url();

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "anthropic",
http_url = %url,
"sending request to Anthropic"
);

let mut headers = self.build_headers(client_headers);
auth.apply_headers(&mut headers)?;

let response = self
.client
.post(url)
.post(url.clone())
.headers(headers)
.body(payload)
.send()
.await?;

#[cfg(feature = "tracing")]
let status_code = response.status().as_u16();

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "anthropic",
http_status_code = status_code,
"received response from Anthropic"
);
{
let span = tracing::Span::current();
span.record("http.url", tracing::field::display(&url));
span.record("http.status_code", response.status().as_u16());
}

if !response.status().is_success() {
let status = response.status();
Expand Down Expand Up @@ -191,37 +179,23 @@ impl crate::providers::Provider for AnthropicProvider {
// Router should have already added stream options to payload
let url = self.messages_url();

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "anthropic",
http_url = %url,
llm_streaming = true,
"sending streaming request to Anthropic"
);

let mut headers = self.build_headers(client_headers);
auth.apply_headers(&mut headers)?;

let response = self
.client
.post(url)
.post(url.clone())
.headers(headers)
.body(payload)
.send()
.await?;

#[cfg(feature = "tracing")]
let status_code = response.status().as_u16();

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "anthropic",
http_status_code = status_code,
llm_streaming = true,
"received streaming response from Anthropic"
);
{
let span = tracing::Span::current();
span.record("http.url", tracing::field::display(&url));
span.record("http.status_code", response.status().as_u16());
}

if !response.status().is_success() {
let status = response.status();
Expand Down
50 changes: 12 additions & 38 deletions crates/braintrust-llm-router/src/providers/azure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,23 @@ impl crate::providers::Provider for AzureProvider {
) -> Result<Bytes> {
let url = self.chat_url(&spec.model)?;

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "azure",
http_url = %url,
"sending request to Azure"
);

let mut headers = self.build_headers(client_headers);
auth.apply_headers(&mut headers)?;

let response = self
.client
.post(url)
.post(url.clone())
.headers(headers)
.body(payload)
.send()
.await?;

#[cfg(feature = "tracing")]
let status_code = response.status().as_u16();

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "azure",
http_status_code = status_code,
"received response from Azure"
);
{
let span = tracing::Span::current();
span.record("http.url", tracing::field::display(&url));
span.record("http.status_code", response.status().as_u16());
}

if !response.status().is_success() {
let status = response.status();
Expand Down Expand Up @@ -222,37 +210,23 @@ impl crate::providers::Provider for AzureProvider {
// Router should have already added stream options to payload
let url = self.chat_url(&spec.model)?;

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "azure",
http_url = %url,
llm_streaming = true,
"sending streaming request to Azure"
);

let mut headers = self.build_headers(client_headers);
auth.apply_headers(&mut headers)?;

let response = self
.client
.post(url)
.post(url.clone())
.headers(headers)
.body(payload)
.send()
.await?;

#[cfg(feature = "tracing")]
let status_code = response.status().as_u16();

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "azure",
http_status_code = status_code,
llm_streaming = true,
"received streaming response from Azure"
);
{
let span = tracing::Span::current();
span.record("http.url", tracing::field::display(&url));
span.record("http.status_code", response.status().as_u16());
}

if !response.status().is_success() {
let status = response.status();
Expand Down
35 changes: 8 additions & 27 deletions crates/braintrust-llm-router/src/providers/bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,38 +221,23 @@ impl BedrockProvider {
url: Url,
payload: Bytes,
auth: &AuthConfig,
stream: bool,
client_headers: &ClientHeaders,
) -> Result<reqwest::Response> {
#[cfg(not(feature = "tracing"))]
let _ = stream;

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "bedrock",
http_url = %url,
llm_streaming = stream,
"sending request to Bedrock"
);

let headers = self.build_headers(&url, payload.as_ref(), auth, client_headers)?;
let response = self
.client
.post(url)
.post(url.clone())
.headers(headers)
.body(payload)
.send()
.await?;

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "bedrock",
http_status_code = response.status().as_u16(),
llm_streaming = stream,
"received response from Bedrock"
);
{
let span = tracing::Span::current();
span.record("http.url", tracing::field::display(&url));
span.record("http.status_code", response.status().as_u16());
}

if !response.status().is_success() {
let status = response.status();
Expand Down Expand Up @@ -294,9 +279,7 @@ impl crate::providers::Provider for BedrockProvider {
} else {
self.converse_url(&spec.model, false)?
};
let response = self
.send_signed(url, payload, auth, false, client_headers)
.await?;
let response = self.send_signed(url, payload, auth, client_headers).await?;
Ok(response.bytes().await?)
}

Expand All @@ -322,9 +305,7 @@ impl crate::providers::Provider for BedrockProvider {
self.converse_url(&spec.model, true)?
};

let response = self
.send_signed(url, payload, auth, true, client_headers)
.await?;
let response = self.send_signed(url, payload, auth, client_headers).await?;
Ok(bedrock_event_stream(response))
}

Expand Down
50 changes: 12 additions & 38 deletions crates/braintrust-llm-router/src/providers/databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,23 @@ impl crate::providers::Provider for DatabricksProvider {
) -> Result<Bytes> {
let url = self.serving_url(&spec.model)?;

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "databricks",
http_url = %url,
"sending request to Databricks"
);

let mut headers = client_headers.to_json_headers();
auth.apply_headers(&mut headers)?;

let response = self
.client
.post(url)
.post(url.clone())
.headers(headers)
.body(payload)
.send()
.await?;

#[cfg(feature = "tracing")]
let status_code = response.status().as_u16();

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "databricks",
http_status_code = status_code,
"received response from Databricks"
);
{
let span = tracing::Span::current();
span.record("http.url", tracing::field::display(&url));
span.record("http.status_code", response.status().as_u16());
}

if !response.status().is_success() {
let status = response.status();
Expand Down Expand Up @@ -154,37 +142,23 @@ impl crate::providers::Provider for DatabricksProvider {

let url = self.serving_url(&spec.model)?;

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "databricks",
http_url = %url,
llm_streaming = true,
"sending streaming request to Databricks"
);

let mut headers = client_headers.to_json_headers();
auth.apply_headers(&mut headers)?;

let response = self
.client
.post(url)
.post(url.clone())
.headers(headers)
.body(payload)
.send()
.await?;

#[cfg(feature = "tracing")]
let status_code = response.status().as_u16();

#[cfg(feature = "tracing")]
tracing::debug!(
target: "bt.router.provider.http",
llm_provider = "databricks",
http_status_code = status_code,
llm_streaming = true,
"received streaming response from Databricks"
);
{
let span = tracing::Span::current();
span.record("http.url", tracing::field::display(&url));
span.record("http.status_code", response.status().as_u16());
}

if !response.status().is_success() {
let status = response.status();
Expand Down
Loading
Loading