Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

feat: add Bedrock Mantle client agent header (#21840)

Celia Chenbd42660cb481
diff --git a/codex-rs/model-provider-info/src/lib.rs b/codex-rs/model-provider-info/src/lib.rs
index 6fca7e6a1f..6856b80b71 100644
--- a/codex-rs/model-provider-info/src/lib.rs
+++ b/codex-rs/model-provider-info/src/lib.rs
@@ -39,6 +39,8 @@ const AMAZON_BEDROCK_PROVIDER_NAME: &str = "Amazon Bedrock";
pub const AMAZON_BEDROCK_PROVIDER_ID: &str = "amazon-bedrock";
pub const AMAZON_BEDROCK_DEFAULT_BASE_URL: &str =
"https://bedrock-mantle.us-east-1.api.aws/openai/v1";
+const AMAZON_BEDROCK_MANTLE_CLIENT_AGENT_HEADER: &str = "x-amzn-mantle-client-agent";
+const AMAZON_BEDROCK_MANTLE_CLIENT_AGENT_VALUE: &str = "codex";
const CHAT_WIRE_API_REMOVED_ERROR: &str = "`wire_api = \"chat\"` is no longer supported.\nHow to fix: set `wire_api = \"responses\"` in your provider config.\nMore info: https://github.com/openai/codex/discussions/7782";
pub const LEGACY_OLLAMA_CHAT_PROVIDER_ID: &str = "ollama-chat";
pub const OLLAMA_CHAT_PROVIDER_REMOVED_ERROR: &str = "`ollama-chat` is no longer supported.\nHow to fix: replace `ollama-chat` with `ollama` in `model_provider`, `oss_provider`, or `--local-provider`.\nMore info: https://github.com/openai/codex/discussions/7782";
@@ -365,7 +367,10 @@ impl ModelProviderInfo {
})),
wire_api: WireApi::Responses,
query_params: None,
- http_headers: None,
+ http_headers: Some(HashMap::from([(
+ AMAZON_BEDROCK_MANTLE_CLIENT_AGENT_HEADER.to_string(),
+ AMAZON_BEDROCK_MANTLE_CLIENT_AGENT_VALUE.to_string(),
+ )])),
env_http_headers: None,
request_max_retries: None,
stream_max_retries: None,
diff --git a/codex-rs/model-provider-info/src/model_provider_info_tests.rs b/codex-rs/model-provider-info/src/model_provider_info_tests.rs
index 54d325c131..abfa40a36a 100644
--- a/codex-rs/model-provider-info/src/model_provider_info_tests.rs
+++ b/codex-rs/model-provider-info/src/model_provider_info_tests.rs
@@ -256,7 +256,10 @@ fn test_create_amazon_bedrock_provider() {
}),
wire_api: WireApi::Responses,
query_params: None,
- http_headers: None,
+ http_headers: Some(maplit::hashmap! {
+ AMAZON_BEDROCK_MANTLE_CLIENT_AGENT_HEADER.to_string() =>
+ AMAZON_BEDROCK_MANTLE_CLIENT_AGENT_VALUE.to_string(),
+ }),
env_http_headers: None,
request_max_retries: None,
stream_max_retries: None,
@@ -268,6 +271,21 @@ fn test_create_amazon_bedrock_provider() {
);
}
+#[test]
+fn test_amazon_bedrock_provider_adds_mantle_client_agent_header() {
+ let api_provider = ModelProviderInfo::create_amazon_bedrock_provider(/*aws*/ None)
+ .to_api_provider(/*auth_mode*/ None)
+ .expect("Amazon Bedrock provider should build API provider");
+
+ assert_eq!(
+ api_provider
+ .headers
+ .get(AMAZON_BEDROCK_MANTLE_CLIENT_AGENT_HEADER)
+ .and_then(|value| value.to_str().ok()),
+ Some(AMAZON_BEDROCK_MANTLE_CLIENT_AGENT_VALUE)
+ );
+}
+
#[test]
fn test_built_in_model_providers_include_amazon_bedrock() {
let providers = built_in_model_providers(/*openai_base_url*/ None);