Skip to content

Use AI and vector search

Organizations can bring credentials for OpenAI, Anthropic, Fireworks, and TypeSafe into the platform without placing secrets in Worker source or Wrangler configuration. Workers call the native AI binding and the platform uses the selected organization-owned connection. Provider accounts, prices, token budgets, and bills remain the organization’s responsibility.

Vector indexes are a separate primitive. They store and search vectors but do not choose a model or generate embeddings. A Worker can compose AI.run() with a Vectorize binding to embed content, store it, search it, and optionally rerank the results.

Add a provider connection

Open AI → Models in the tenant console and add an OpenAI, Anthropic, Fireworks, or TypeSafe API key. A key is encrypted at rest and represented only by a short fingerprint after saving. Each organization can configure at most one connection for each provider type; the human-readable connection name does not change the model identifier used by Workers.

Select the provider name to open its Overview or Settings. Overview shows the provider identity, model prefix, and every Worker whose active deployment contains an AI binding. Settings contains the credential fingerprint, Replace API key, and named confirmation for removal. Replacing the key keeps the provider connection and Worker bindings intact. A stored credential is not a successful authentication check against the upstream provider.

Use Observability from the provider detail to open invocations filtered to ai.run and the currently bound Workers. That workspace provides retained trace evidence, calling Worker and task, duration, outcome, and provider-reported input, output, and cache token counts without maintaining a second bounded activity history on the provider page.

The model name begins with the provider type and the remainder is sent to that provider unchanged. OpenAI supports chat-completion and embeddings through this binding. Fireworks supports chat-completion, embeddings, and reranking. Anthropic currently supports message generation. TypeSafe’s Jev model answers structured decision questions: choose among options, score criteria, or estimate whether a statement is true. Use it when your application needs a decision rather than a free-form response. The organization owns the provider account, API key, usage, and bill; the platform only supplies the encrypted credential and tenant-scoped Worker plumbing. For Fireworks:

The Models page for adding an organization-owned inference provider

const answer = await env.AI.run(
  "fireworks/accounts/fireworks/models/glm-5p3-flash",
  { messages: [{ role: "user", content: "Summarize this document." }] },
);

const embeddings = await env.AI.run(
  "fireworks/accounts/fireworks/models/qwen3-embedding-8b",
  { text: [document], dimensions: 1024 },
);

const ranked = await env.AI.run(
  "fireworks/accounts/fireworks/models/qwen3-reranker-8b",
  { query, documents, top_n: 10 },
);

For a TypeSafe decision request, preserve the provider’s native state and named question structure:

const decision = await env.AI.run("typesafe/jev-latest", {
  state: {
    message: "Our checkout has returned 500 errors for twenty minutes.",
    affectedOrders: 42,
  },
  questions: {
    urgency: {
      type: "score",
      instructions: "How urgently should the team respond?",
      criteria: ["Can wait", "Needs attention today", "Act immediately"],
    },
    customerImpact: {
      type: "noul",
      instructions: "Customers are currently unable to complete purchases.",
    },
  },
});

Task selection follows the input contract rather than a model-name allowlist. messages selects generation, text or input selects embeddings, query plus documents selects reranking, and state plus questions selects decisions. Pass { task: "..." } as the third argument to AI.run() when an unusual provider payload is ambiguous.

The platform does not add a model-result cache or own provider spend. Provider options such as prompt-cache keys pass through in generation payloads, and provider usage/cache fields pass through in generation responses. Embedding responses use the Workers AI-style { shape, data, usage } structure so their vectors can be inserted directly.

The Models service normalizes those provider usage fields for telemetry without recording prompts or responses. Open Observability → Overview to compare inference count, failures, input/output tokens, cache reads and writes, and p95 provider duration for the selected time and Workers. Open an invocation to see the model and token counts on its ai.run span alongside the rest of the application trace. Cached input is also part of the provider’s input total; it is shown separately to make cache use visible, not added to that total again.

Declare the binding in Wrangler:

[ai]
binding = "AI"

The same binding is available as this.env.AI inside a Durable Object. Its requests use a grant scoped to the owning organization, Worker, and active deployment. The shard manager issues the grant; neither application code nor the shared runtime receives its signing key or the provider credential.

Create and bind a vector index

Use the tenant console under AI → Vector indexes, or use ordinary Wrangler commands after connecting Wrangler:

npx wrangler vectorize create documents --dimensions 1024 --metric cosine
npx wrangler vectorize info documents

Then bind the index by name:

[[vectorize]]
binding = "VECTORIZE"
index_name = "documents"

The index detail separates Overview from Settings. Overview shows the immutable dimensions and distance metric, current vector count, description, and the binding and active deployment for every Worker using that exact index. Its Observability action opens invocations filtered to vectorize.* for those Workers. Settings contains named, destructive deletion; the console does not expose raw vector contents or an arbitrary vector editor.

The Worker-facing binding implements describe(), insert(), upsert(), query(), queryById(), getByIds(), and deleteByIds(). Wrangler’s create, list, get, delete, insert, upsert, query, list-vectors, get-vectors, delete-vectors, and info commands use the same organization-scoped service.

The Vector indexes page for creating an organization-scoped index

const { data } = await env.AI.run(
  "fireworks/accounts/fireworks/models/qwen3-embedding-8b",
  { text: [document], dimensions: 1024 },
);
await env.VECTORIZE.upsert([
  { id: documentId, values: data[0], metadata: { title } },
]);

const query = await env.AI.run(
  "fireworks/accounts/fireworks/models/qwen3-embedding-8b",
  { text: [searchText], dimensions: 1024 },
);
const matches = await env.VECTORIZE.query(query.data[0], {
  topK: 10,
  returnMetadata: "all",
});

Indexes use 1–1,536 dimensions and cosine, Euclidean, or dot-product distance. Writes contain at most 1,000 vectors and queries return at most 100 matches. Vector IDs are unique within an index; a namespace can partition searches but does not create a second identity space. Metadata filters currently perform exact field matches.

Indexes provide exact local search over an organization-scoped SQLite catalog. They are appropriate for development and moderate evaluation workloads, not a distributed approximate-nearest-neighbor service. Index data is not replicated or automatically failed over.

Security, limits, and verification

Worker bindings are resource-scoped capabilities. Worker code receives neither the provider credential nor the vector service credential, and index management continues to require organization RBAC.

Usage & limits enforces provider count, inference count, index count, stored vector count, and vector operation limits. Growth fails closed if quota enforcement is unavailable; deletion remains possible. Models and Vector operations appear in organization-scoped observability and platform telemetry, but provider credentials, prompts, vectors, and returned content are not recorded.

The photo example uses these capabilities for structured descriptions and tags. Operators can validate provider and vector integration using capability checks.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close