{"record":{"id":"7624de992ca4b628","repo":"openai/openai-python","slug":"the-bedrock-bearer-credential-must-not-be-empty-7624de","errorCode":null,"errorMessage":"The Bedrock bearer credential must not be empty.","messagePattern":"The Bedrock bearer credential must not be empty\\.","errorType":"exception","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"src/openai/providers/bedrock.py","lineNumber":442,"sourceCode":"    )\n\n    normalized_profile = _normalize_optional_string(profile)\n    if profile is not None and normalized_profile is None:\n        raise OpenAIError(\"The Bedrock AWS `profile` must not be empty.\")\n\n    if (access_key_id is None) != (secret_access_key is None) or (session_token is not None and access_key_id is None):\n        raise OpenAIError(\n            \"Static AWS credentials require both `access_key_id` and `secret_access_key`. \"\n            \"A `session_token` may only be used with both.\"\n        )\n    if access_key_id is not None and (not access_key_id.strip() or not cast(str, secret_access_key).strip()):\n        raise OpenAIError(\"Static AWS credentials require non-empty `access_key_id` and `secret_access_key` values.\")\n    if session_token is not None and not session_token.strip():\n        raise OpenAIError(\"A static AWS `session_token` must not be empty when provided.\")\n\n    explicit_api_key = not isinstance(api_key, NotGiven) and api_key is not None\n    if explicit_api_key and (not isinstance(api_key, str) or not api_key.strip()):\n        raise OpenAIError(\"The Bedrock bearer credential must not be empty.\")\n    if explicit_api_key and token_provider is not None:\n        raise OpenAIError(\"The `api_key` and `token_provider` options are mutually exclusive. Configure only one.\")\n\n    explicit_bearer = explicit_api_key or token_provider is not None\n    aws_modes = sum(\n        (\n            access_key_id is not None,\n            normalized_profile is not None,\n            credential_provider is not None,\n        )\n    )\n    if aws_modes > 1:\n        raise OpenAIError(\n            \"Bedrock authentication is ambiguous. Configure exactly one explicit AWS mode: static credentials, \"\n            \"profile, or credential provider.\"\n        )\n    if explicit_bearer and aws_modes:\n        raise OpenAIError(","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/providers/bedrock.py#L424-L460","documentation":"An `api_key` was explicitly passed to `bedrock()` (as a bearer credential for Bedrock Mantle) but it is empty or whitespace-only. The SDK validates this before constructing the client so requests fail fast instead of sending an Authorization header AWS rejects.","triggerScenarios":"bedrock(api_key='') or api_key='  ', or passing api_key from an env var that is defined but blank.","commonSituations":"OPENAI_API_KEY-style env var set to an empty string in CI, or api_key=os.environ.get('API_KEY', '') forwarded unconditionally.","solutions":["Pass a real bearer token or omit api_key / set it to None so other credential sources apply","Normalize: api_key=os.environ.get('API_KEY') or None"],"exampleFix":"# before\nbedrock(api_key=os.environ.get('OPENAI_API_KEY', ''))\n# after\nbedrock(api_key=os.environ.get('OPENAI_API_KEY') or None)","handlingStrategy":"validation","validationCode":"api_key = os.environ.get('OPENAI_API_KEY') or None\nbedrock(api_key=api_key)","typeGuard":"def bearer_key_ok(k: object) -> bool:\n    return k is None or (isinstance(k, str) and bool(k.strip()))","tryCatchPattern":null,"preventionTips":["Fail fast at startup if a required key is missing","Never pass api_key=''"],"tags":["bedrock","api-key","bearer","validation"],"backgroundTag":"empty-credential-value","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}