Reference · API
AWS Bedrock invoke model
Last updated
Call **foundation models inside AWS** — Claude, Llama, Titan, and others — with IAM auth instead of vendor API keys in app code.
Call **foundation models inside AWS** — Claude, Llama, Titan, and others — with IAM auth instead of vendor API keys in app code.
#When to use
Conceptual pattern — exact model IDs and request fields vary by provider on Bedrock.
#Endpoint (conceptual)
POST https://bedrock-runtime.{region}.amazonaws.com/model/{modelId}/invokeAnthropic-on-Bedrock uses a messages-style body; others use provider-specific JSON.
#Request shape (sketch)
{
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 512,
"messages": [{"role": "user", "content": "Summarize this ticket."}]
}Sign with **AWS Signature V4** (SDK handles this).
#Python sketch (boto3)
import boto3, json
client = boto3.client("bedrock-runtime", region_name="us-east-1")
body = {
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Hello"}],
}
resp = client.invoke_model(
modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
body=json.dumps(body),
)
print(json.loads(resp["body"].read()))#Common pitfalls
| Pitfall | Fix |
|---------|-----|
| Wrong region for model ID | Enable model access in Bedrock console per region |
| Copy-paste direct API bodies | Bedrock wraps Anthropic/OpenAI shapes differently |
| No IAM least privilege | Scope `bedrock:InvokeModel` to specific model ARNs |
| Ignoring latency / quotas | Request quota increases; use async for batch |