{"record":{"id":"99ef2f01783f8665","repo":"openai/openai-python","slug":"a-static-aws-session-token-must-not-be-empty-whe","errorCode":null,"errorMessage":"A static AWS `session_token` must not be empty when provided.","messagePattern":"A static AWS `session_token` must not be empty when provided\\.","errorType":"exception","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"src/openai/providers/bedrock.py","lineNumber":438,"sourceCode":"        _parse_bedrock_endpoint_hostname(configured_base_url.host) if configured_base_url is not None else None\n    )\n    resolved_endpoint: BedrockEndpoint = endpoint or (\n        canonical_endpoint[0] if canonical_endpoint is not None else \"mantle\"\n    )\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, \"","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/providers/bedrock.py#L420-L456","documentation":"A `session_token` was supplied alongside static credentials but it is empty or whitespace-only. Temporary AWS credentials require a real session token, so a blank one is rejected up front.","triggerScenarios":"bedrock(access_key_id=..., secret_access_key=..., session_token='') or session_token='  '.","commonSituations":"Using long-lived keys but forwarding an AWS_SESSION_TOKEN env var that is blank, or truncating the token during copy-paste (session tokens are long).","solutions":["Omit session_token entirely if using long-lived IAM keys","Supply the full, non-empty session token when using temporary credentials"],"exampleFix":"# before\nbedrock(ak, sk, session_token=os.getenv('AWS_SESSION_TOKEN', ''))\n# after\nbedrock(ak, sk, session_token=os.environ.get('AWS_SESSION_TOKEN') or None)","handlingStrategy":"validation","validationCode":"session_token = os.environ.get('AWS_SESSION_TOKEN') or None\nbedrock(access_key_id=ak, secret_access_key=sk, session_token=session_token)","typeGuard":"def token_ok(st: str | None) -> bool:\n    return st is None or bool(st.strip())","tryCatchPattern":null,"preventionTips":["Only set session_token when using temporary credentials","Check for truncation when pasting long tokens"],"tags":["bedrock","aws-credentials","session-token","validation"],"backgroundTag":"empty-credential-value","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}