Functions

assistant-message

fn (content: Vec<Map>): Message
fn (text: Str): Message

Helper to create an assistant message for the Converse API.

Example

msg ::aws::bedrock::converse/assistant-message("The capital of France is Paris.")
// => Message({role: "assistant", content: [{text: "The capital of France is Paris."}]})

converse

fn (model_id: Str, messages: Vec<Map>, system: Vec<Map>?, inference_config: Map?, tool_config: Map?, guardrail_config: Map?, opts: Map): ConverseResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>, system: Vec<Map>?, inference_config: Map?, opts: Map): ConverseResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>, opts: Map): ConverseResponse | ::aws::core/AwsError
fn (model_id: Str, text: Str, opts: Map): ConverseResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>, system: Vec<Map>?, inference_config: Map?, tool_config: Map?, guardrail_config: Map?): ConverseResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>, system: Vec<Map>?, inference_config: Map?): ConverseResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>, system: Vec<Map>?): ConverseResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>): ConverseResponse | ::aws::core/AwsError
fn (model_id: Str, text: Str): ConverseResponse | ::aws::core/AwsError

Use the Bedrock Converse API for a unified interface across all models.

The Converse API works with any Bedrock model (Claude, Titan, Llama, Mistral, etc.) using the same message format.

Example

// Simple text conversation
result ::aws::bedrock::converse/converse("us.amazon.nova-micro-v1:0", "What is 2+2?")
content result.output.message.content
text first(content).text
// => "4"

// With message history
messages [
    {role: "user", content: [{text: "My name is Alice"}]},
    {role: "assistant", content: [{text: "Hello Alice!"}]},
    {role: "user", content: [{text: "What is my name?"}]}
]
result ::aws::bedrock::converse/converse("us.amazon.nova-micro-v1:0", messages)

// Check usage metrics
result.usage.inputTokens   // => 15
result.usage.outputTokens  // => 5

converse-stream

fn (model_id: Str, messages: Vec<Map>, system: Vec<Map>?, inference_config: Map?, tool_config: Map?, opts: Map): ::hot::http/HttpResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>, system: Vec<Map>?, opts: Map): ::hot::http/HttpResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>, opts: Map): ::hot::http/HttpResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>, system: Vec<Map>?, inference_config: Map?, tool_config: Map?): ::hot::http/HttpResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>, system: Vec<Map>?): ::hot::http/HttpResponse | ::aws::core/AwsError
fn (model_id: Str, messages: Vec<Map>): ::hot::http/HttpResponse | ::aws::core/AwsError

Use the Bedrock Converse API with streaming response.

Returns the raw HTTP response with an event stream body. Note: Streaming requires parsing the AWS Event Stream binary format.

Example

::converse ::aws::bedrock::converse

response ::converse/converse-stream(
  "anthropic.claude-3-haiku-20240307-v1:0",
  [::converse/user-message("Write a haiku about rivers.")],
  [{text: "You are a poet."}]
)

// The body is the AWS Event Stream binary format
events ::aws::eventstream/parse-stream(response.body)
map(events, ::aws::eventstream/get-header(%, ":event-type"))

image-content

fn (format: Str, source_bytes: Str): Map

Helper to create an image content block for the Converse API.

Example

block ::aws::bedrock::converse/image-content("png", "iVBORw0KGgo=")
// => {image: {format: "png", source: {bytes: "..."}}}

inference-config

fn (max_tokens: Int, temperature: Dec?, top_p: Dec?, stop_sequences: Vec<Str>?): Map
fn (max_tokens: Int, temperature: Dec): Map
fn (max_tokens: Int): Map

Helper to create inference configuration for the Converse API.

Example

// Max tokens only
config ::aws::bedrock::converse/inference-config(100)
// => {maxTokens: 100}

// Max tokens with temperature
config ::aws::bedrock::converse/inference-config(200, 0.5)
// => {maxTokens: 200, temperature: 0.5}

text-content

fn (text: Str): Map

Helper to create a text content block for the Converse API.

Example

block ::aws::bedrock::converse/text-content("Hello")
// => {text: "Hello"}

user-message

fn (content: Vec<Map>): Message
fn (text: Str): Message

Helper to create a user message for the Converse API.

Example

msg ::aws::bedrock::converse/user-message("What is the capital of France?")
// => Message({role: "user", content: [{text: "What is the capital of France?"}]})

Types

ContentBlock

ContentBlock type {
    text: Str?,
    image: Map?,
    tool_use: Map?,
    tool_result: Map?
}

ConverseResponse

ConverseResponse type {
    output: Map?,
    stop_reason: StopReason?,
    usage: Map?,
    metrics: Map?
}

ConverseStreamEvent

ConverseStreamEvent type {
    message_start: Map?,
    content_block_start: Map?,
    content_block_delta: Map?,
    content_block_stop: Map?,
    message_stop: Map?,
    metadata: Map?
}

Message

Message type {
    role: Role,
    content: Vec<ContentBlock>
}

Role

Role type "user" | "assistant"

StopReason

StopReason type "end_turn" | "tool_use" | "max_tokens" | "stop_sequence" | "guardrail_intervened" | "content_filtered"

ToolConfig

ToolConfig type {
    tools: Vec<Map>,
    tool_choice: Map?
}