> ## 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 API Part 1

> Explains connecting applications to Amazon Bedrock, compares control plane and runtime APIs, recommends using AWS SDKs, and provides examples for model invocation and configuration.

In this lesson we cover how to connect your application to Amazon Bedrock so it can expose generative AI capabilities. We'll explain the problem, the two Bedrock APIs, a recommended SDK workflow, and provide short examples you can reuse.

We'll cover:

* The problem: how to connect your app to Bedrock
* The solution: Bedrock API and Bedrock Runtime API
* A simpler workflow using the AWS SDK
* A short demonstration and expected results
* A summary and a hands-on lab

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tJmUiudNjsCWp_bm/images/Introduction-to-Amazon-Bedrock/Getting-Started-With-Amazon-Bedrock/Bedrock-API-Part-1/lecture-flow-bedrock-workflow-demo-results.jpg?fit=max&auto=format&n=tJmUiudNjsCWp_bm&q=85&s=70d93e7cafee7d00006d702800aac364" alt="A slide titled &#x22;Lecture Flow&#x22; showing a sequence of rounded blue boxes connected by arrows. The boxes read Problem (How to connect your app to Bedrock), Solution (Bedrock API), Workflow (AWS SDK Bedrock Client), Demonstration, Results (Faster application development), and Key Takeaway (Control and Runtime API)." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Getting-Started-With-Amazon-Bedrock/Bedrock-API-Part-1/lecture-flow-bedrock-workflow-demo-results.jpg" />
</Frame>

## The problem: How do we connect our application to Amazon Bedrock?

If your application needs to provide generative AI features, it must interact programmatically with Bedrock. Typical responsibilities include:

* Sending prompts to models to perform inference.
* Managing available models, guardrails, and configuration (control plane).

These are distinct operation types and therefore map to different APIs: one for configuration/setup (control plane) and one for model invocation (inference/runtime).

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tJmUiudNjsCWp_bm/images/Introduction-to-Amazon-Bedrock/Getting-Started-With-Amazon-Bedrock/Bedrock-API-Part-1/connect-app-to-bedrock-challenges.jpg?fit=max&auto=format&n=tJmUiudNjsCWp_bm&q=85&s=bec3012e1fc369e480242097fe6636fe" alt="A presentation slide titled &#x22;Problem: How To Connect Your App to Bedrock&#x22; showing four numbered panels describing developer challenges. The panels note problems like programmatic interaction, separate model/prompt management, the need for a consistent interface, and the complexity of raw APIs." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Getting-Started-With-Amazon-Bedrock/Bedrock-API-Part-1/connect-app-to-bedrock-challenges.jpg" />
</Frame>

If you call HTTP endpoints directly you must handle:

* SigV4 request signing
* Retries and exponential backoff
* Serialization and deserialization of JSON payloads
* Error handling and status parsing

That burden is why most developers use an SDK to avoid reinventing those features.

## The solution: Bedrock API vs Bedrock Runtime API

There are two APIs to know:

| API | Purpose | Typical operations |
| - | - | - |
| `bedrock` (control plane) | Setup and configuration | Create knowledge bases, manage guardrails, register models |
| `bedrock-runtime` (runtime/inference) | Model execution and response generation | Invoke models, stream outputs, handle inference responses |

Both are REST-over-HTTPS, require IAM authentication using SigV4, and return JSON responses.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tJmUiudNjsCWp_bm/images/Introduction-to-Amazon-Bedrock/Getting-Started-With-Amazon-Bedrock/Bedrock-API-Part-1/bedrock-runtime-api-setup-execution.jpg?fit=max&auto=format&n=tJmUiudNjsCWp_bm&q=85&s=84d3ab1ad11040d276f069d005710ecb" alt="A diagram titled &#x22;Solution: Bedrock and Bedrock Runtime API&#x22; showing two API types: Setup/Configuration (Bedrock API — control plane operations like creating knowledge bases and managing guardrails) and Execution/Inference (Bedrock Runtime API — invoking models and generating responses). It also notes common characteristics such as REST over HTTPS, IAM authentication, and JSON responses." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Getting-Started-With-Amazon-Bedrock/Bedrock-API-Part-1/bedrock-runtime-api-setup-execution.jpg" />
</Frame>

### Direct REST (manual) — what it looks like

If you choose to call the runtime endpoint manually, you perform an HTTPS POST with a SigV4 Authorization header and a JSON body. Example (pseudocode):

```http theme={null}
POST /model/invoke HTTP/1.1
Host: bedrock.us-east-1.amazonaws.com
Authorization: AWS4-HMAC-SHA256 Credential=AKIA..., SignedHeaders=host;x-amz-date, Signature=...
Content-Type: application/json

{
  "prompt": "Explain Amazon Bedrock and how to call it programmatically."
}
```

And you receive a JSON response with the model output. When you do this manually you must implement signing, retries, and error handling yourself.

## Recommended workflow: Use the AWS SDK

The AWS SDKs (e.g., Boto3 for Python, AWS SDK for JavaScript/TypeScript, AWS SDK for Java, .NET, PHP) provide a higher-level interface that:

* Performs SigV4 signing automatically
* Serializes requests and deserializes JSON responses
* Handles retries, timeouts, and credential resolution
* Exposes simple method calls for runtime and control-plane actions

Install the SDK for your language (pip, npm, Maven/Gradle, NuGet, etc.) and create separate clients for `bedrock` and `bedrock-runtime` to keep configuration and inference operations distinct.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tJmUiudNjsCWp_bm/images/Introduction-to-Amazon-Bedrock/Getting-Started-With-Amazon-Bedrock/Bedrock-API-Part-1/sdk-python-aws-bedrock-s3-ec2.jpg?fit=max&auto=format&n=tJmUiudNjsCWp_bm&q=85&s=ec5d9339e1fa153422f9960560bdc283" alt="A diagram titled &#x22;Workflow: Software Developer Kit (SDK)&#x22; showing Python code connected to the AWS SDK for Python. Arrows indicate the SDK calling APIs for Amazon Bedrock, Amazon S3, and AWS EC2, with labels like &#x22;Dependency&#x22; and &#x22;Simple method calls like invoke-model()&#x22;." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Getting-Started-With-Amazon-Bedrock/Bedrock-API-Part-1/sdk-python-aws-bedrock-s3-ec2.jpg" />
</Frame>

### Example: creating a Bedrock Runtime client in Python (Boto3)

Notes before the example:

* The Python SDK is called Boto3.
* Use the service name `bedrock-runtime` for inference calls and `bedrock` for control-plane calls.
* Configure credentials and region (shared credentials file, environment variables, or IAM role).
* Ensure the Bedrock service is available in the chosen region.

Example code:

```python theme={null}
import boto3

# Runtime client for model invocation (inference)
inference_client = boto3.client(
    "bedrock-runtime",
    region_name="us-east-1"
)

# Control plane client for management/configuration
config_client = boto3.client(
    "bedrock",
    region_name="us-east-1"
)
```

A few practical tips:

* Name your clients clearly (`inference_client`, `config_client`) to avoid confusion.
* Verify the service is available in your AWS Region: consult the official AWS Regional Services List.
* The SDK handles SigV4 signing; you do not need to implement signing logic manually.

<Callout icon="lightbulb" color="#1CB2FE">
  Use separate SDK clients for runtime (`bedrock-runtime`) and control-plane (`bedrock`) operations. The SDK handles signing, retries, and serialization, which simplifies development and reduces errors.
</Callout>

## Short demonstration and expected results

Typical demo flow:

1. Use the control-plane client (`bedrock`) to list available models or configure a knowledge base.
2. Use the runtime client (`bedrock-runtime`) to invoke a model with a text prompt.
3. Receive a JSON response containing the generated text (or streamed tokens if using streaming APIs).
4. Handle errors (throttling, validation errors) by relying on the SDK's retry/backoff behavior and inspecting exception details.

Expected outcomes:

* Faster development: no manual signing or JSON plumbing.
* Cleaner code: method calls instead of raw HTTP requests.
* More robust apps: built-in retries and credential management.

## Summary and next steps

* Problem: Applications need programmatic access to models and configuration.
* Solution: Two APIs — control-plane (`bedrock`) and runtime (`bedrock-runtime`) — each mapped to separate API endpoints and SDK clients.
* Recommendation: Use the AWS SDK for your language (Boto3 shown for Python) to handle signing, retries, and serialization.
* Next: Follow a hands-on lab to list models, invoke a model, and inspect outputs. For production, integrate error handling, rate-limit awareness, and logging.

## Links and References

* Amazon Bedrock documentation: [https://docs.aws.amazon.com/bedrock/](https://docs.aws.amazon.com/bedrock/)
* AWS SDKs: [https://aws.amazon.com/tools/](https://aws.amazon.com/tools/)
* Boto3 documentation: [https://boto3.amazonaws.com/v1/documentation/api/latest/index.html](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html)
* Signature Version 4 signing process: [https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/introduction-to-amazon-bedrock/module/4f0b1655-3751-4724-a6eb-78d06f3753a7/lesson/1ce69feb-f856-416e-ba31-60f7fe548fa7" />
</CardGroup>


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