# What does a typical API request look like for generating text using Amazon Bedrock (for instance, what parameters and payload are needed)?

Source: https://zilliz.com/ai-faq/what-does-a-typical-api-request-look-like-for-generating-text-using-amazon-bedrock-for-instance-what-parameters-and-payload-are-needed
Author: zilliz

A typical API request to generate text using Amazon Bedrock consists of an HTTP POST request to a model-specific endpoint with JSON payload containing generation parameters. The core components include specifying the model ID, setting content headers, and providing a structured request body with inputs like the prompt text and generation controls. For example, when using Anthropic's Claude model, you'd send a request to the Claude endpoint with parameters controlling output length and creativity.

The request requires two main parts: headers and a JSON payload. In the headers, you specify `Content-Type: application/json` and `Accept: application/json` to indicate JSON input and expected response format. The endpoint URL includes your AWS region and model ID, such as `https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-v2/invoke`. The JSON body for Claude typically contains a `prompt` field formatted as `"\n\nHuman: [your input]\n\nAssistant:"`, along with parameters like `max_tokens_to_sample` (response length limit), `temperature` (creativity control from 0=deterministic to 1=random), and `top_p` (probability mass cutoff). Some models may require additional parameters like `stop_sequences` to define stopping points.

For example, a Claude request body might include:
```json
{
 "prompt": "\n\nHuman: Explain quantum computing in simple terms\n\nAssistant:",
 "max_tokens_to_sample": 300,
 "temperature": 0.5,
 "top_p": 0.9
}
```
The response returns a JSON object containing the generated text in a `completion` field, along with metadata like token counts and stop reason. Developers must handle AWS authentication via SigV4 signing and ensure proper IAM permissions for the Bedrock service. Different foundation models in Bedrock (like AI21 Labs' Jurassic or Meta's Llama) have slightly varying parameter names and requirements, so checking the specific model's documentation is crucial.
