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

## Why

Amazon Bedrock Mantle needs a stable client-agent header so requests
from the built-in Bedrock provider can be identified as coming from
Codex for safety stack.

## What changed

- Added `x-amzn-mantle-client-agent: codex` to the built-in Amazon
Bedrock provider default HTTP headers.
This commit is contained in:
Celia Chen
2026-05-08 16:58:41 -07:00
committed by GitHub
parent 0c8d42525e
commit bd42660cb4
2 changed files with 25 additions and 2 deletions

View File

@@ -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,

View File

@@ -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);