---
title: "Invoke Model"
method: POST
path: "/model/invoke"
tags: ["Model Invocation"]
---

# Invoke Model

`POST /model/invoke`

## Endpoint to Invoke a Model on Bedrock with Standardized Input
This endpoint allows users to invoke a model on Bedrock using either a simple text prompt or a series of messages. The request can include various optional parameters to control the model's behavior.

***

## Request Body

| Parameter       | Type                                                      | Description                                                                                           |
|-----------------|-----------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
| model_name      | str                                                       | The name of the model to invoke. Must be one of the supported models.                                  |
| prompt          | Union[str, List[Dict[str, Union[str, List[Dict[str, str]]]]]] | A simple text prompt (str) or a list of messages (see below for message format).                       |
| max_tokens      | Optional[int]                                             | The maximum number of tokens to generate in the response.                                             |
| temperature     | Optional[float]                                           | Sampling temperature to use. Higher values make the output more random.                                |
| top_p           | Optional[float]                                           | Probability threshold for nucleus sampling.                                                           |
| top_k           | Optional[int]                                             | The number of highest probability vocabulary tokens to keep for top-k filtering.                       |
| stop_sequences  | Optional[List[str]]                                       | Sequences where the generation will stop.                                                             |
| system_prompts  | Optional[List[Dict[str, str]]]                            | A list of dictionaries for system prompts, each with a single key "text".                              |

***

#### Message Format for Prompt

| Parameter | Type              | Description                                                        |
|-----------|-------------------|--------------------------------------------------------------------|
| role      | str               | The role of the message sender (e.g., "user", "assistant").        |
| content   | List[Dict[str, str]] | A list of dictionaries, each containing a "text" key with the message content. |

***

#### Example 1: Simple Text Prompt
```json
{ 
    "model_name": "example_model", 
    "prompt": "Translate the following text to French: 'Hello, how are you?'", 
    "max_tokens": 100, 
    "temperature": 0.7, 
    "top_p": 0.9, 
    "top_k": 50, 
    "stop_sequences": ["\n"] 
}
```

#### Example 2: Messages

```json
{ 
    "model_name": "example_model", 
    "prompt": [ 
        { 
            "role": "user", 
            "content": [{"text": "What is the weather like today?"}] 
        }, 
        { 
            "role": "assistant", 
            "content": [{"text": "The weather is sunny with a high of 25°C."}] 
        } 
    ], 
    "max_tokens": 100, 
    "temperature": 0.7, 
    "top_p": 0.9, 
    "top_k": 50, 
    "stop_sequences": ["\n"], 
    "system_prompts": [ 
        { 
            "text": "Your system prompt here" 
        } 
    ] 
}
```

***

## Response Body

| Field          | Type   | Description                          |
|----------------|--------|--------------------------------------|
| output_text    | str    | The generated text.                  |
| input_tokens   | str    | The number of input tokens used.     |
| output_tokens  | str    | The number of output tokens generated.|

***

#### Errors

- **400 Bad Request**: If the request parameters are invalid.
- **401 Unauthorized**: If the authorization header is missing or invalid.
- **500 Internal Server Error**: If there is an unexpected error during model invocation.

***

#### Notes

## Request body

- InvokeModelRequest
  - `model_name` string, required
  - `prompt` union, required
    - string
    - object[]
  - `max_tokens` integer
  - `temperature` number
  - `top_p` number
  - `top_k` integer
  - `stop_sequences` string[]
  - `system_prompts` object[]

## Response `200`

Successful Response

- unknown

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.dev/aws-samples/apis/generative-ai-foundational-platform-api.md) · [All operations](https://skmtc.dev/aws-samples/apis/generative-ai-foundational-platform-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/aws-samples/generative-ai-foundational-platform-api/revisions/8831d08902e9/schema)
