Skip to content
renkudocs
GuidesAI models

AI models

renku/ai exposes createAI from agents/models/ai-sdk and AI SDK generateText, streamText and Output. Applications choose models, authorized input, budgets and response handling. Model inference is separate from the MCP transport exposed by renku/mcp.

On this page

Configure worker.env.AI with bindings.ai() in renku.config.ts. Construct the provider inside the request or Durable Object operation using its environment. Pass a Workers AI @cf/ model, an AI Gateway catalog ID, or dynamic/<route>.

Catalog IDs use the gateway's spelling; configured dynamic routes require their gateway ID. renku pins Agents 0.29.0 and AI SDK 7. The provider is beta. See https://developers.cloudflare.com/agents/models/ai-sdk/ for the upstream API.

src/answer.ts
import { createAI, generateText } from "renku/ai";

export async function answer(env: { AI: Ai }, prompt: string, signal: AbortSignal) {
  const ai = createAI({ binding: env.AI });
  const { text } = await generateText({
    model: ai("@cf/zai-org/glm-4.7-flash"),
    prompt,
    maxOutputTokens: 256,
    maxRetries: 0,
    abortSignal: AbortSignal.any([signal, AbortSignal.timeout(10000)]),
  });
  return text;
}

createAI accepts gateway options such as id, metadata and cacheTtl. Model options can provide a fallback list; per-call overrides use providerOptions.cloudflare. streamText accepts the same model and exposes toTextStreamResponse().

Outside a Worker, createAI also accepts accountId and apiToken instead of binding. Keep credentials on the server. No workers-ai-provider or ai-gateway-provider package is needed.

A registered MCP tool can call generateText using createAI after checking application authorization.

MCP transport, OAuth and model inference remain separate concerns; registering a tool does not require an inference call. antgrade's six conversation tools use existing domain authorities and do not generate text.

Its Clef reaction ranking uses the specialized state/questions decision schema through AI.run; createAI's chat and reranking interfaces do not represent that schema. Keep that direct binding call until the provider supports Clef decisions.

You can call a configured AI model from server code and choose budgets, cancellation and streaming behavior.

Continue to durable agents

← All guides · Explore the docs source (access required) →