Skip to content

InvokeModel

Source: src/AWS/Bedrock/InvokeModel.ts

Runtime binding for bedrock-runtime:InvokeModel — run inference with a model-specific request body (text, image, or embedding models).

Bind one or more model references inside a function runtime to get a callable that invokes the model with a raw payload. The binding grants the function bedrock:InvokeModel scoped to exactly the bound models. A model reference may be a foundation-model id, a cross-region inference profile id (e.g. us.amazon.nova-micro-v1:0), or a full Bedrock ARN.

Prefer Converse for conversational models — it is model-agnostic. InvokeModel is for model-native payloads (embeddings, image generation, or provider-specific request features).

Model access is an account entitlement — enable the model in the Bedrock console (Model access) before invoking, otherwise calls fail with AccessDeniedException.

// init
const invokeModel = yield* Bedrock.InvokeModel("us.amazon.nova-micro-v1:0");
// runtime — body is the raw Nova messages-v1 payload
const result = yield* invokeModel({
contentType: "application/json",
accept: "application/json",
body: JSON.stringify({
messages: [{ role: "user", content: [{ text: "Say hello." }] }],
inferenceConfig: { maxTokens: 64 },
}),
});
// result.body is a byte Stream of the JSON response
const json = JSON.parse(
yield* Stream.mkString(Stream.decodeText(result.body)),
);