{"record":{"id":"bbd2768eec8265f5","repo":"BerriAI/litellm","slug":"invalid-model-format-expected-format-model-bedr","errorCode":null,"errorMessage":"Invalid model format. Expected format: 'model=bedrock/agentcore/arn:aws:bedrock-agentcore:region:account:runtime/runtime_id'","messagePattern":"Invalid model format\\. Expected format: 'model=bedrock/agentcore/arn:aws:bedrock-agentcore:region:account:runtime/runtime_id'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/bedrock/chat/agentcore/transformation.py","lineNumber":163,"sourceCode":"            headers=headers,\n            optional_params=optional_params,\n            request_data=request_data,\n            api_base=api_base,\n            model=model,\n            stream=stream,\n            fake_stream=fake_stream,\n            api_key=api_key,\n        )\n\n    def _get_agent_runtime_arn(self, model: str) -> str:\n        \"\"\"\n        Extract ARN from model string\n        model = \"agentcore/arn:aws:bedrock-agentcore:us-west-2:888602223428:runtime/hosted_agent_r9jvp-3ySZuRHjLC\"\n        returns: \"arn:aws:bedrock-agentcore:us-west-2:888602223428:runtime/hosted_agent_r9jvp-3ySZuRHjLC\"\n        \"\"\"\n        parts: Final = model.split(\"/\", 1)\n        if len(parts) != 2 or parts[0] != \"agentcore\":\n            raise ValueError(\n                \"Invalid model format. Expected format: 'model=bedrock/agentcore/arn:aws:bedrock-agentcore:region:account:runtime/runtime_id'\"\n            )\n        return parts[1]\n\n    def _extract_region_from_arn(self, arn: str) -> str:\n        \"\"\"\n        Extract region from ARN\n        arn:aws:bedrock-agentcore:us-west-2:888602223428:runtime/hosted_agent_r9jvp-3ySZuRHjLC\n        returns: us-west-2\n        \"\"\"\n        parts: Final = arn.split(\":\")\n        if len(parts) >= 4:\n            return parts[3]\n        raise ValueError(f\"Invalid ARN format: {arn}\")\n\n    def _get_runtime_session_id(self, optional_params: dict) -> str:\n        \"\"\"\n        Get or generate runtime session ID (must be 33+ chars)","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/bedrock/chat/agentcore/transformation.py#L145-L181","documentation":"Bedrock AgentCore chat requires the model string to start with the literal prefix 'agentcore/' followed by the full runtime ARN. _get_agent_runtime_arn splits the model on the first '/' and raises this ValueError when the prefix is missing, wrong, or there is no slash at all. It fires before any network call, so it is purely a caller-input/config error.","triggerScenarios":"litellm.completion with model=\"arn:aws:bedrock-agentcore:us-west-2:123:runtime/abc\" (bare ARN, no prefix); model=\"agentcore\" (no slash); model=\"bedrock-agentcore/arn:...\" or any other first component that is not exactly 'agentcore'.","commonSituations":"Porting code from boto3 bedrock-agentcore where the bare ARN is accepted; pasting the runtime ARN from the AgentCore console straight into model; typos in the prefix; proxy deployment configs that store only the ARN in the model field.","solutions":["Use the full router form model=\"bedrock/agentcore/<runtime-arn>\" (or \"agentcore/<runtime-arn>\" if calling the Bedrock provider directly)","Copy the runtime ARN verbatim from the Bedrock AgentCore console — it must contain the arn:aws:bedrock-agentcore:region:account:runtime/<id> shape","If routing through the LiteLLM proxy, put the correctly formatted three-segment string in the deployment's model_name, not just the ARN"],"exampleFix":"// before\nresp = litellm.completion(model=\"arn:aws:bedrock-agentcore:us-west-2:888602223428:runtime/hosted_agent_r9jvp\", messages=msgs)\n\n// after\nresp = litellm.completion(model=\"bedrock/agentcore/arn:aws:bedrock-agentcore:us-west-2:888602223428:runtime/hosted_agent_r9jvp\", messages=msgs)","handlingStrategy":"validation","validationCode":"model = \"bedrock/agentcore/arn:aws:bedrock-agentcore:us-west-2:888602223428:runtime/hosted_agent_x\"\n_, _, rest = model.split(\"/\", 2)\nif not rest.startswith(\"agentcore/\"):\n    raise ValueError(f\"model must be 'bedrock/agentcore/<runtime-arn>', got {model!r}\")\nresp = litellm.completion(model=model, messages=msgs)","typeGuard":"def is_agentcore_model_string(model: str) -> bool:\n    \"\"\"True when model carries the required 'agentcore/<arn>' shape.\"\"\"\n    parts = model.split(\"/\", 1)\n    return len(parts) == 2 and parts[0] == \"agentcore\"","tryCatchPattern":"try:\n    resp = litellm.completion(model=model, messages=msgs)\nexcept ValueError as e:\n    if \"Invalid model format\" in str(e) and \"agentcore\" in str(e):\n        raise ConfigError(f\"Fix deployment config: use bedrock/agentcore/<runtime-arn>, got {model!r}\") from e\n    raise","preventionTips":["Centralize AgentCore model strings in one config module with a documented format","Copy runtime ARNs from the AgentCore console, never type them by hand","Add config validation at app startup for every bedrock/agentcore model entry"],"tags":["bedrock","agentcore","model-string","input-validation","aws"],"backgroundTag":"invalid-model-identifier","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}