v1

latestOpenAPI 3.0.22026-07-173834119.9 KB
Model Invocation

Invoke Model

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

ParameterTypeDescription
model_namestrThe name of the model to invoke. Must be one of the supported models.
promptUnion[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_tokensOptional[int]The maximum number of tokens to generate in the response.
temperatureOptional[float]Sampling temperature to use. Higher values make the output more random.
top_pOptional[float]Probability threshold for nucleus sampling.
top_kOptional[int]The number of highest probability vocabulary tokens to keep for top-k filtering.
stop_sequencesOptional[List[str]]Sequences where the generation will stop.
system_promptsOptional[List[Dict[str, str]]]A list of dictionaries for system prompts, each with a single key "text".

Message Format for Prompt

ParameterTypeDescription
rolestrThe role of the message sender (e.g., "user", "assistant").
contentList[Dict[str, str]]A list of dictionaries, each containing a "text" key with the message content.

Example 1: Simple Text Prompt

{ 
    "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

{ 
    "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

FieldTypeDescription
output_textstrThe generated text.
input_tokensstrThe number of input tokens used.
output_tokensstrThe 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

post/model/invoke

Request body

model_namestring required
max_tokensinteger
temperaturenumber
top_pnumber
top_kinteger
stop_sequencesstring[]
system_promptsobject[]

Example request

{
  "system_prompts": [
    {
      "text": "You are a helpful assistant."
    }
  ]
}

Response

Successful Response

{"stackTrail":"paths:/model/invoke:post:responses:200:content:application/json:schema","oasType":"schema","type":"unknown"}