Summary audio
Spoken summary — press play to read along: the line being spoken stays near the top.
Study notes
AWS Bedrock API Request Fundamentals
**I. Prerequisites for API Request** To make a request to AWS Bedrock, you need three core components:
- Client: An interface to access Bedrock (typically using the Boto3 Python module).
- Model ID / Inference Profile ID: The identifier for the specific model you want to run.
- User Message: A specially formatted object containing the text input you want to feed into the model.
**II. Model Identification and Routing**
- Region Specificity: Model IDs are tied to specific AWS regions. A model available in one region (e. g. , US West 2) may not be available in another (e. g. , US East 1).
- The Problem: If you request a model in the wrong region, you will receive an error.
- Solution: Inference Profiles:
- Inference profiles are used to automatically route requests to a region where the chosen model is guaranteed to be hosted.
- Usage: Instead of using the specific Model ID, you provide the Inference Profile ID in your request. AWS handles the automatic routing.
**III. Message Structure** Messages are the structured data used to communicate with the model, containing both input and output text.
- User Message:
- Contains the text you want to feed into the model.
- Always has a role of "user. "
- Structure: A dictionary containing a role and a content property.
- Assistant Message:
- Contains the text generated by the model.
- Always has a role of "assistant. "
- Structure: Similar to the user message, containing a role and a content property.
- The content Property:
- This property is always a list.
- The list allows a single message to contain multiple parts (e. g. , text combined with an image).
**IV. Making and Interpreting the Request**
- API Call: The request is made using the client. converse() method.
- Parameters: You must pass the model ID (or Inference Profile ID) and the messages (a list containing your user message).
- Extracting Generated Text: The model response is a complex object. To retrieve the generated text, you must navigate the structure:
Response → output → message → content[0] → text
Takeaways
- To request a Bedrock API call, you must provide a Client, a Model ID or Inference Profile ID, and a structured User Message.
- Inference Profiles are used to automatically route requests to the correct region, bypassing the need to manually select a region-specific Model ID.
- Messages (User or Assistant) are structured with a role and a content property.
- The content property is always a list, allowing a single message to contain multiple parts (e. g. , text combined with an image).
- The API call is made using client. converse(), and the generated text is extracted by navigating the response structure: Response → output → message → content[0] → text.
Flashcards 10 cards
Question
click to reveal · ←/→
Answer
click to flip back
Knowledge check 6 questions