> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bedrock Playground and API Demonstrations

> Guide to exploring Amazon Bedrock models in the console Playground and calling Bedrock programmatically from Python using boto3, with examples and best practices

This lesson demonstrates how to explore models in the Amazon Bedrock console Playground and how to call Bedrock programmatically from Python using the AWS SDK (boto3). Follow the console walkthrough to pick models and experiment interactively, then reuse the same model choices in your application code.

## Explore models in the Bedrock console

Open the AWS Management Console and navigate to Bedrock (type `Bedrock` in the search bar or find it under Recently visited). From the Bedrock console you can inspect available models for your region using the Model catalog.

Tip: Select the AWS Region closest to your workload (for example, `us-east-1` / N. Virginia, Seoul, Mumbai, or São Paulo) using the region selector in the console. Model availability varies by region.

Under Test → Playground you can open the interactive Playground. The UI prompts you to select a model; here we choose a foundation model available in this region (for the demo we use Amazon's Nova Micro on-demand).

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/4OlDw81IoiRnJTCQ/images/Introduction-to-Amazon-Bedrock/Introduction-to-Text-Generation-With-Amazon-Bedrock/Bedrock-Playground-and-API-Demonstrations/aws-bedrock-select-model-list-cursor.jpg?fit=max&auto=format&n=4OlDw81IoiRnJTCQ&q=85&s=a52cb48feae9e0cb6831ab930a12340e" alt="A screenshot of the Amazon Bedrock &#x22;Select model&#x22; dialog in the AWS console showing a list of model providers and models (e.g., Titan Image Generator, Nova) with input/output options. A large mouse cursor is hovering over the model list." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Introduction-to-Text-Generation-With-Amazon-Bedrock/Bedrock-Playground-and-API-Demonstrations/aws-bedrock-select-model-list-cursor.jpg" />
</Frame>

After selecting a model, click Apply to open the Playground. The Playground provides:

* Chat (multi-turn conversations)
* Single prompt (one-shot requests)
* Compare mode (send the same prompt to multiple models and view outputs side-by-side)

Run a quick prompt, for example: "Explain the difference between the Bedrock Runtime API and the Bedrock API." The Playground returns the generated response along with token counts and latency, which helps you evaluate models before integrating them into code.

You can also jump from a Model Catalog entry directly into the Playground. If you inspect Anthropic’s Claude Sonnet 4.5 and it fits your needs (modalities, languages, token limits), use the “Open in Playground” link to launch the Playground pre-selected with that model.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/4OlDw81IoiRnJTCQ/images/Introduction-to-Amazon-Bedrock/Introduction-to-Text-Generation-With-Amazon-Bedrock/Bedrock-Playground-and-API-Demonstrations/bedrock-anthropic-claude-sonnet-45-details.jpg?fit=max&auto=format&n=4OlDw81IoiRnJTCQ&q=85&s=604482cea743f3f4ff36ffb95ace463f" alt="A screenshot of the Amazon Bedrock web console showing the Model catalog page for Anthropic's &#x22;Claude Sonnet 4.5&#x22; with a details table listing categories, input/output modalities, max input, and supported languages. The left sidebar navigation (Discover, Labs, Test, Infer, Tune) is visible and a large cursor arrow points at the details." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Introduction-to-Text-Generation-With-Amazon-Bedrock/Bedrock-Playground-and-API-Demonstrations/bedrock-anthropic-claude-sonnet-45-details.jpg" />
</Frame>

## Call Bedrock from Python (boto3)

Once you’ve selected models in the console, switch to your code editor and call Bedrock from your application. The example below uses the Bedrock Runtime client and the chat-friendly `converse` method with a unified messages structure. Replace `region_name` and `model_id` with values appropriate for your account and chosen model.

```python theme={null}
import boto3

# Create the Bedrock Runtime client (adjust region as needed)
inference_client = boto3.client("bedrock-runtime", region_name="us-east-1")

# A structured prompt improves consistency and reduces iteration time.
user_prompt = """
context:
you are helping a developer learn Amazon Bedrock generative AI service.
the developer already knows python and has some experience with the AWS SDK for Python.

role:
act as a clear technical instructor.

instruction:
explain the difference between the Bedrock Runtime SDK client and the Bedrock SDK client and when to use each one.

output format:
return the answer as a short paragraph of up to a maximum of 4 sentences.
"""

# Unified messages format (suitable for high-level "converse" interfaces)
messages = [
    {
        "role": "user",
        "content": [
            {"text": user_prompt}
        ]
    }
]

# Choose the foundation model you want to use
model_id = "meta.llama3-8b-instruct-v1:0"

# Call the Converse API
response = inference_client.converse(modelId=model_id, messages=messages)

# Extract the generated text from the response safely
text = ""
try:
    text = response["output"]["message"]["content"][0]["text"]
except Exception:
    # Fallback: stringify the whole response for debugging
    text = str(response)

print(f"{model_id}:\n{text}\n")
```

Best practices shown in the example:

* Use a structured prompt (context, role, instruction, output format) for consistent, high-quality outputs.
* Use the unified messages format when available to maintain portability between chat-enabled models.
* Use descriptive variable names (for example, `inference_client`) to make code more readable.
* Replace `model_id` and `region_name` with the correct values for your account and region.

Important: SDK method names and response shapes can vary with SDK versions and model providers. Some examples use method names like `invoke_model` or other variants. If you encounter a different method or response format, consult the relevant documentation for exact API signatures.

<Callout icon="lightbulb" color="#1CB2FE">
  When choosing a region, select the region closest to your workload and ensure the models you need are available there. Also confirm your AWS credentials are configured and that the IAM principal has permission to call Bedrock APIs.
</Callout>

## Quick reference: when to use which API style

| Use case | Recommended API style |
| - | - |
| Multi-turn chat or conversational workflows | Use the chat-style `converse` method with the unified messages format |
| Single-shot completion or provider-specific calls | Use provider-specific single-turn methods (for example, `invoke_model` in some examples) — check the model docs |
| Experimenting interactively | Use the Bedrock Playground in the console to compare outputs, tokens, and latency |

## Links and references

* Boto3 (AWS SDK for Python) documentation: [https://boto3.amazonaws.com/v1/documentation/api/latest/index.html](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html)
* Amazon Bedrock developer guide: [https://docs.aws.amazon.com/bedrock/latest/devguide/what-is-bedrock.html](https://docs.aws.amazon.com/bedrock/latest/devguide/what-is-bedrock.html)
* AWS CLI and SDK credential configuration: [https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)

## Summary

* Use the Bedrock Model Catalog and Playground to discover models and run quick experiments (single prompt, multi-turn chat, or compare mode).
* Structure prompts with clear context, role, instruction, and output format to improve results and iteration speed.
* Call Bedrock from Python using the AWS SDK (boto3); prefer the unified messages format with `converse` for chat-style interactions.
* Always verify region/model availability and check SDK/model documentation for exact method names and response structures.

That concludes this demonstration. Try the Bedrock Playground and the API calls hands-on to validate your prompts and chosen models.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/introduction-to-amazon-bedrock/module/aa0ee0de-373b-464f-a99b-a014b9898118/lesson/e4c83a40-6aa8-43e5-8c82-1c52a08d7a0a" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.