1import type * as bedrock from "@distilled.cloud/aws/bedrock-runtime";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4
5/**
6 * The `Converse` request with the binding-injected `modelId` made optional:
7 * it defaults to the first bound model id and may be overridden per call
8 * with any of the bound model ids.
9 */
10export interface ConverseRequest extends Omit<
11 bedrock.ConverseRequest,
12 "modelId"
13> {
14 /**
15 * The model to run inference on for this call. Must be one of the model
16 * ids the binding was created with (IAM is scoped to exactly those).
17 * @default the first bound model id
18 */
19 modelId?: string;
20}
21
22/**
23 * Runtime binding for `bedrock-runtime:Converse` — Amazon Bedrock's unified
24 * messages API that works across all conversational foundation models.
25 *
26 * Bind one or more model references inside a function runtime to get a
27 * callable that sends messages to the model. The binding grants the function
28 * `bedrock:InvokeModel` scoped to exactly the bound models. A model reference
29 * may be a foundation-model id, a cross-region inference profile id (e.g.
30 * `us.amazon.nova-micro-v1:0`), or a full Bedrock ARN (application inference
31 * profile, imported model, prompt version, ...).
32 *
33 * Model access is an account entitlement — enable the model in the Bedrock
34 * console (Model access) before invoking, otherwise calls fail with
35 * `AccessDeniedException`. Many newer models are only invocable through a
36 * cross-region inference profile id, not their bare foundation-model id.
37 *
38 * ### Conversing with a Model
39 * **Example:** Send a Single Prompt
40 * ```typescript
41 * // init
42 * const converse = yield* Bedrock.Converse("us.amazon.nova-micro-v1:0");
43 *
44 * // runtime
45 * const result = yield* converse({
46 * messages: [{ role: "user", content: [{ text: "Say hello." }] }],
47 * inferenceConfig: { maxTokens: 64 },
48 * });
49 * const text = result.output.message.content[0]?.text;
50 * ```
51 *
52 * **Example:** Bind Multiple Models and Pick Per Call
53 * ```typescript
54 * const converse = yield* Bedrock.Converse(
55 * "us.amazon.nova-micro-v1:0",
56 * "us.anthropic.claude-sonnet-4-20250514-v1:0",
57 * );
58 *
59 * const result = yield* converse({
60 * modelId: "us.anthropic.claude-sonnet-4-20250514-v1:0",
61 * messages: [{ role: "user", content: [{ text: "Summarize this." }] }],
62 * });
63 * ```
64 *
65 * **Example:** System Prompt and Inference Config
66 * ```typescript
67 * const result = yield* converse({
68 * system: [{ text: "You answer in exactly one word." }],
69 * messages: [{ role: "user", content: [{ text: "What color is the sky?" }] }],
70 * inferenceConfig: { maxTokens: 16, temperature: 0 },
71 * });
72 * ```
73 *
74 * @binding
75 */
76export interface Converse extends Binding.Service<
77 Converse,
78 "AWS.Bedrock.Converse",
79 (
80 model: string,
81 ...additionalModels: string[]
82 ) => Effect.Effect<
83 (
84 request: ConverseRequest,
85 ) => Effect.Effect<bedrock.ConverseResponse, bedrock.ConverseError>
86 >
87> {}
88export const Converse = Binding.Service<Converse>("AWS.Bedrock.Converse");