Skip to content
25K
Console

Ai

The Ai component lets you add a Cloudflare Workers AI binding to your app.

Minimal example

sst.config.ts
const ai = new sst.cloudflare.Ai("MyAi");

You can link AI to a worker.

sst.config.ts
new sst.cloudflare.Worker("MyWorker", {
handler: "./index.ts",
link: [ai],
url: true
});

Once linked, you can use the SDK to interact with the AI binding.

index.ts
import { Resource } from "sst";
const result = await Resource.MyAi.run("@cf/meta/llama-3-8b-instruct", {
prompt: "What is the origin of the phrase 'Hello, World'"
});

Constructor

new Ai(name, args?, opts?)

Parameters

SDK

Use the SDK in your runtime to interact with your infrastructure.


Bindings

When you link an AI binding, it will be available to the worker and you can interact with it using its API methods.

index.ts
import { Resource } from "sst";
const result = await Resource.MyAi.run("@cf/meta/llama-3-8b-instruct", {
prompt: "What is the origin of the phrase 'Hello, World'"
});