openai/openai-python · error · OpenAIError
Refusing to sign a Bedrock request for an origin other than
Error message
Refusing to sign a Bedrock request for an origin other than the configured provider URL.
What it means
The SigV4 auth's request validator (used by both sync and async prepare paths) requires the request URL's origin to equal the provider's configured base_url origin before it will sign. Signing a request to an arbitrary origin with your AWS credentials would leak them, so it raises instead.
Source
Thrown at src/openai/providers/bedrock.py:208
request.headers["Authorization"] = f"Bearer {await self._resolve_token_async()}"
class _BedrockSigV4Auth:
def __init__(
self,
*,
config: BedrockAwsAuthConfig,
base_url: httpx2.URL,
auth: BedrockAwsAuth | None = None,
) -> None:
self._config = config
self._base_url = base_url
self._auth = auth
def _validate_request(self, request: httpx2.Request) -> bytes:
_assert_provider_owns_authorization(request)
if not _same_origin(request.url, self._base_url):
raise OpenAIError(
"Refusing to sign a Bedrock request for an origin other than the configured provider URL."
)
canonical_endpoint = _parse_bedrock_endpoint_hostname(request.url.host)
if canonical_endpoint is not None:
endpoint, region = canonical_endpoint
expected_endpoint = "runtime" if self._config.service == "bedrock" else "mantle"
if endpoint != expected_endpoint:
raise OpenAIError(
f"The Bedrock {endpoint} hostname does not match the selected `{expected_endpoint}` endpoint."
)
if region != self._config.region:
raise OpenAIError(
f"The Bedrock endpoint region `{region}` does not match the SigV4 region `{self._config.region}`."
)
return _body_for_signing(request)
View on GitHub (pinned to 9917c6e28e)
Solutions
- Provide a fully-qualified base_url with scheme and host (https://bedrock-runtime.<region>.amazonaws.com).
- Verify no code mutates request.url between client and provider.
Example fix
# before provider = bedrock(region="us-east-1", base_url="bedrock-runtime") # after provider = bedrock(region="us-east-1", base_url="https://bedrock-runtime.us-east-1.amazonaws.com")
Defensive patterns
Strategy: validation
Validate before calling
from httpx2 import URL u = URL(base_url) assert u.scheme and u.host, "base_url must include scheme and host"
Type guard
def is_absolute_url(base_url: str) -> bool:
u = URL(base_url)
return bool(u.scheme and u.host) Try / catch
try:
client = OpenAI(provider=bedrock(region=region, base_url=base_url, aws_credentials=creds))
except OpenAIError as e:
if "origin" in str(e):
client = OpenAI(provider=bedrock(region=region, aws_credentials=creds))
else:
raise Prevention
- Use absolute https URLs for provider base_url.
- Avoid interceptors that rewrite request hosts before signing.
- Centralize base_url construction in one config module.
When it happens
Trigger: base_url without a host (relative path) making httpx2 resolve the request against a different default origin; or custom transports/interceptors redirecting the URL to another host before signing.
Common situations: Migrating Azure-style path-only base_url usage to Bedrock; trailing-slash or scheme typos; a proxy layer rewriting hosts.
Related errors
- Refusing to authenticate a Bedrock request for an origin oth
- Bedrock SigV4 authentication requires a replayable request b
- Bedrock SigV4 authentication does not support automatic redi
- The Bedrock {endpoint} hostname does not match the selected
- The Bedrock endpoint region `{region}` does not match the Si
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/e9b73be1f4eb36c5.
Report an issue: GitHub.