The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type * as bedrock from "@distilled.cloud/aws/bedrock-runtime"; |
| 2 | import * as Binding from "alchemy/Binding"; |
| 3 | import type * as Effect from "effect/Effect"; |
| 4 | |
| 5 | /** |
| 6 | * The `InvokeModel` request with the binding-injected `modelId` made |
| 7 | * optional: it defaults to the first bound model id and may be overridden |
| 8 | * per call with any of the bound model ids. |
| 9 | * |
| 10 | * `body` is the raw, model-specific request payload (e.g. the Anthropic |
| 11 | * Messages API shape for Claude models, the Nova messages-v1 shape for |
| 12 | * Amazon Nova) — there is no auto-marshalling. The response `body` is a |
| 13 | * byte `Stream` of the model-specific JSON response. |
| 14 | */ |
| 15 | export interface InvokeModelRequest extends Omit<bedrock.InvokeModelRequest, "modelId"> { |
| 16 | /** |
| 17 | * The model to run inference on for this call. Must be one of the model |
| 18 | * ids the binding was created with (IAM is scoped to exactly those). |
| 19 | * @default the first bound model id |
| 20 | */ |
| 21 | modelId?: string; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Runtime binding for `bedrock-runtime:InvokeModel` — run inference with a |
| 26 | * model-specific request body (text, image, or embedding models). |
| 27 | * |
| 28 | * Bind one or more model references inside a function runtime to get a |
| 29 | * callable that invokes the model with a raw payload. The binding grants the |
| 30 | * function `bedrock:InvokeModel` scoped to exactly the bound models. A model |
| 31 | * reference may be a foundation-model id, a cross-region inference profile |
| 32 | * id (e.g. `us.amazon.nova-micro-v1:0`), or a full Bedrock ARN. |
| 33 | * |
| 34 | * Prefer {@link Converse} for conversational models — it is model-agnostic. |
| 35 | * `InvokeModel` is for model-native payloads (embeddings, image generation, |
| 36 | * or provider-specific request features). |
| 37 | * |
| 38 | * Model access is an account entitlement — enable the model in the Bedrock |
| 39 | * console (Model access) before invoking, otherwise calls fail with |
| 40 | * `AccessDeniedException`. |
| 41 | * |
| 42 | * ### Invoking a Model |
| 43 | * **Example:** Invoke with a Model-Native Payload |
| 44 | * ```typescript |
| 45 | * // init |
| 46 | * const invokeModel = yield* Bedrock.InvokeModel("us.amazon.nova-micro-v1:0"); |
| 47 | * |
| 48 | * // runtime — body is the raw Nova messages-v1 payload |
| 49 | * const result = yield* invokeModel({ |
| 50 | * contentType: "application/json", |
| 51 | * accept: "application/json", |
| 52 | * body: JSON.stringify({ |
| 53 | * messages: [{ role: "user", content: [{ text: "Say hello." }] }], |
| 54 | * inferenceConfig: { maxTokens: 64 }, |
| 55 | * }), |
| 56 | * }); |
| 57 | * // result.body is a byte Stream of the JSON response |
| 58 | * const json = JSON.parse( |
| 59 | * yield* Stream.mkString(Stream.decodeText(result.body)), |
| 60 | * ); |
| 61 | * ``` |
| 62 | * |
| 63 | * @binding |
| 64 | */ |
| 65 | export interface InvokeModel extends Binding.Service< |
| 66 | InvokeModel, |
| 67 | "AWS.Bedrock.InvokeModel", |
| 68 | ( |
| 69 | model: string, |
| 70 | ...additionalModels: string[] |
| 71 | ) => Effect.Effect< |
| 72 | ( |
| 73 | request: InvokeModelRequest, |
| 74 | ) => Effect.Effect<bedrock.InvokeModelResponse, bedrock.InvokeModelError> |
| 75 | > |
| 76 | > {} |
| 77 | export const InvokeModel = Binding.Service<InvokeModel>("AWS.Bedrock.InvokeModel"); |