Skip to content
AnswerWell geo Documentation

Research · 10 min read · Answerwell

Edge Model Catalog: Agent Inference, RAG Stages, Prefix Caching, and Plan Limits

How to choose Workers AI and AI Search models, route via AI Gateway, use session affinity for prompt caching, and handle paid-plan gates and deprecations.

This page summarizes Cloudflare Workers AI and related product docs on which models to run where (direct inference, AI Search RAG, or AI Gateway), how prefix caching and session headers affect multi-turn agents, and what billing, rate limits, and deprecations constrain production choices.

Workers AI model catalog: what @cf/… IDs mean and how to call them

Section titled “Workers AI model catalog: what @cf/… IDs mean and how to call them”

Workers AI exposes models as stable IDs such as @cf/moonshotai/kimi-k2.6 or @cf/deepseek-ai/deepseek-v4-flash-0731. You can invoke them through the Workers binding (env.AI.run()), the REST API (/ai/run or /v1/chat/completions), or through AI Gateway on the same endpoints.

Use Kimi K2.6 through the Workers AI binding (env.AI.run()), the REST API at /ai/run, or the OpenAI-compatible endpoint at /v1/chat/completions. You can also use AI Gateway with any of these endpoints.

— Cloudflare, Moonshot AI Kimi K2.6 now available on Workers AI

The platform validates token counts for prompts and responses against each model’s context window (prompt tokens plus response tokens), not character counts. If the total exceeds the window, the request errors—set max_tokens with your prompt length in mind.

We’ve updated the Workers AI text generation models to include context windows and limits definitions and changed our APIs to estimate and validate the number of tokens in the input prompt, not the number of characters.

— Cloudflare, Workers AI larger context windows

Usage is serverless per model: each model maps input units (tokens, images, audio, and so on) to Neurons, with per-model list prices on individual model pages.

You will still only pay for what you consume: Workers AI inference is serverless, and not billed by the hour.

— Cloudflare, Workers AI updated pricing

Which hosted model fits coding agents, million-token context, or fast vision?

Section titled “Which hosted model fits coding agents, million-token context, or fast vision?”

Pick from capabilities and limits documented on model pages and changelog posts—not from marketing names alone.

Workload Example model ID Context (tokens) Notes from docs
Long-horizon code / agents @cf/deepseek-ai/deepseek-v4-pro-0813, @cf/deepseek-ai/deepseek-v4-flash-0731 1,048,576 First Workers AI models at 1M context; Paid plan or prepaid AI Gateway credits
Multimodal agent + vision @cf/deepseek-ai/deepseek-v4.1-flash-1017 1,048,576 Vision, function calling, reasoning_effort; 20 RPM default (50 with prepaid Gateway credits)
Frontier open MoE (general agentic) @cf/moonshotai/kimi-k2.6 262,144 Vision, tool calling, reasoning; Workers Paid required
Code-optimized Kimi @cf/moonshotai/kimi-k2.7-code 262,144 Reasoning always on; Workers Paid required
Efficient open MoE @cf/google/gemma-4-26b-a4b-it 256,000 Vision, thinking mode, function calling; remains on Free plan per capacity notice
Low-latency vision inline @cf/moondream/moondream3.1-9B-A2B 32,000 Edge vision; documented p50 end-to-end latencies for simple images
Multi-agent throughput @cf/nvidia/nemotron-3-120b-a12b 32,000 Tool calling; prompt caching via x-session-affinity

DeepSeek V4 Flash and DeepSeek V4 Pro are the first Workers AI models with a full one million (1,048,576) token context window. Use them for long-horizon agentic workflows, large codebases, and multi-step reasoning that exceed the context limits of every other model hosted on the platform.

— Cloudflare, DeepSeek V4 Flash and Pro now available on Workers AI

For coding specifically, @cf/moonshotai/kimi-k2.7-code is positioned as the code-tuned K2 variant with the same API surface as K2.6 but different pricing on cached input.

If you are migrating from Kimi K2.6, note the following: K2.7 Code is optimized for coding tasks with improved benchmark performance and reasoning efficiency … API usage is identical — no parameter changes required

— Cloudflare, Moonshot AI Kimi K2.7 Code now available on Workers AI

Workers Free vs Paid: models that return 403

Section titled “Workers Free vs Paid: models that return 403”

Several resource-intensive catalog models are not available on the Workers Free plan. Requests fail with HTTP 403 (internal error 5035) until you upgrade to Workers Paid (from $5/month, still including 10,000 free Neurons per day) or use eligible prepaid AI Gateway credits where the model allows it.

The following models now require the Workers Paid plan: @cf/moonshotai/kimi-k2.6, @cf/moonshotai/kimi-k2.7-code, @cf/zai-org/glm-5.2

— Cloudflare, Select models now require the Workers Paid plan

Many other models—including @cf/google/gemma-4-26b-a4b-it and @cf/nvidia/nemotron-3-120b-a12b—remain available on Free per that notice. DeepSeek V4 family pages state Paid access required (Workers Paid or prepaid AI Gateway credits).

AI Search models: embedding, generation, rerank, and external providers

Section titled “AI Search models: embedding, generation, rerank, and external providers”

AI Search configuration assigns a model per stage. Only the embedding model is fixed after creation; generation, query rewriting, and reranking can be changed later.

Stage Editable after creation? Role
Embedding model No Vector embeddings for semantic search
Generation model Yes Final answer from retrieved context
Query rewriting model Yes Query reformulation (optional)
Reranking model Yes Re-order hits by relevance (optional)
AI Gateway Yes Route generation, rewrite, and external calls

AI Search leverages Workers AI models in the following stages: … Embedding … Query rewriting (optional) … Reranking (optional) … Generation

— Cloudflare, Models

Default Workers AI models vs Bring Your Own Keys through AI Gateway

Section titled “Default Workers AI models vs Bring Your Own Keys through AI Gateway”

By default, AI Search uses Workers AI models. To call OpenAI, Anthropic, or others, add provider keys to AI Gateway (Bring Your Own Keys), connect that gateway in AI Search settings, then pick gateway-backed model IDs compatible with the OpenAI Chat Completions shape for generation and rewrite steps.

By default, AI Search uses Workers AI models. To use models from other providers, such as OpenAI or Anthropic, add your provider keys to AI Gateway and select those models in AI Search.

— Cloudflare, Use models from other providers

Supported embedding and reranking IDs must appear on Supported models. Listed text generation Workers AI models for AI Search include DeepSeek V4 Flash/Pro, GPT-OSS variants, Qwen 3.8 27B, and Kimi K2.7 Code—with context windows matching the catalog (for example 1,048,576 for DeepSeek V4 Flash).

AI Search now supports six additional Workers AI models for text generation … These models run on Workers AI, so they do not require an additional provider key.

— Cloudflare, New Workers AI text generation models in AI Search

Embeddings and multimodal RAG: Qwen, EmbeddingGemma, image in query

Section titled “Embeddings and multimodal RAG: Qwen, EmbeddingGemma, image in query”

For text indexing, docs highlight @cf/qwen/qwen3-embedding-0.6b (1,024 dimensions, up to 4,096 input tokens) and @cf/google/embeddinggemma-300m (768 dimensions, 512 input tokens, low-latency).

Qwen3-Embedding-0.6B supports up to 4,096 input tokens, making it a good fit for indexing longer text chunks. EmbeddingGemma-300M from Google produces 768-dimension vectors and is optimized for low-latency embedding workloads.

— Cloudflare, New Workers AI models for text generation and embedding in AI Search

Multimodal search supports @cf/qwen/qwen3-vl-embedding-2b and google-ai-studio/gemini-embedding-2; search and chat requests can include images via the REST API and public endpoint.

AI Search supports the @cf/qwen/qwen3-vl-embedding-2b and google-ai-studio/gemini-embedding-2 multimodal embedding models. Search and chat requests can include images through the REST API and public endpoint.

— Cloudflare, AI Search is generally available

Smart Default leaves embedding and generation choices to Cloudflare’s recommended set, which can change over time; explicit model IDs give you full control and predictable deprecation planning.

Prefix caching and session headers: Workers AI vs AI Gateway Auto Router

Section titled “Prefix caching and session headers: Workers AI vs AI Gateway Auto Router”

Multi-turn agents resend large shared prefixes (system prompt, tools, history). Prefix caching skips recomputing the shared prefill, improving time to first token and throughput; cached input tokens bill below regular input on supporting models.

Prefix caching (also called prefix caching) is a performance optimization that allows Workers AI to respond faster to requests with prompts that share common inputs. It reduces Time to First Token (TTFT) and increases Tokens Per Second (TPS) throughput by reusing previously computed input tensors instead of reprocessing them from scratch.

— Cloudflare, Prompt caching

Cache hits require routing to the same model instance that holds tensors. On Workers AI, send header x-session-affinity with a stable session id.

Prefix caching only works when a request routes to the same model instance that holds the cached tensors. To maximize cache hit rates, send the x-session-affinity header with a unique identifier for your session or agent.

— Cloudflare, Prompt caching

Structure prompts so static content (system, tools) is first; avoid timestamps in the system prompt because one token mismatch invalidates the prefix from that point.

When traffic goes through AI Gateway Auto Router, use cf-aig-session-id so one turn (user message plus tool follow-ups) stays on one model and can use prompt caching. Without it, each request may land on a different model and cannot reuse cache. Send cf-aig-turn-id to mark turns yourself, or cf-aig-no-session-affinity: true to disable affinity. Auto Router may switch models at turn boundaries when benefit outweighs cache loss.

For multi-turn conversations, such as chats or coding agents, send a cf-aig-session-id header with each request. Auto Router then keeps the same model for an entire turn, so requests can take advantage of prompt caching.

— Cloudflare, Session affinity

Auto Router only picks models allowed by cf-aig-allowed-models or cf-aig-allowed-providers; the Auto Router doc lists additional Workers AI and third-party IDs (OpenAI, Anthropic, xAI, and others).

Verify caching in the response usage object (cached_tokens on later turns when the prefix is large enough to cache).

Kimi K2 family: migration, reasoning fields, and deprecation

Section titled “Kimi K2 family: migration, reasoning fields, and deprecation”

If you still call @cf/moonshotai/kimi-k2.5, plan a move before alias and deprecation: on May 30, 2026, requests alias to @cf/moonshotai/kimi-k2.6 at higher price.

Requests will be automatically aliased to Kimi K2.6 on May 30, 2026, which has a higher price.

— Cloudflare, Planned model deprecations on Workers AI

K2.6 changes reasoning controls vs K2.5:

K2.6 uses chat_template_kwargs.thinking to control reasoning, replacing chat_template_kwargs.enable_thinking. K2.6 returns reasoning content in the reasoning field, replacing reasoning_content

— Cloudflare, Moonshot AI Kimi K2.6 now available on Workers AI

On newer Moonshot IDs such as moonshotai/kimi-k3 (Workers AI model page examples), reasoning_effort replaces the K2.x thinking parameter.

Model pages document per-model reasoning modes (for example DeepSeek V4 Flash: none, low, high default, max; Kimi K2.7 Code: reasoning always on).

Workers AI periodically retires older Llama, Gemma, and Mistral catalog entries while keeping many -fast and -lora variants. See Workers AI changelog and Planned model deprecations on Workers AI for dates and replacement guidance (@cf/zai-org/glm-4.7-flash, @cf/google/gemma-4-26b-a4b-it, @cf/moonshotai/kimi-k2.6 are named as migration targets in the catalog changelog summary).

AI Search follows its own model lifecycle (production → announcement → end of life); Smart Default may auto-upgrade generation models when configured.

Rerankers, pooling, and JSON mode (adjacent catalog features)

Section titled “Rerankers, pooling, and JSON mode (adjacent catalog features)”

RAG stacks on Workers AI can add @cf/baai/bge-reranker-base after vector retrieval to score query–passage pairs. For BGE embedding models, docs recommend explicit pooling: cls for accuracy; cls vectors are not backward compatible with default mean pooling—re-index if you switch.

JSON Mode is supported only on a defined subset of models and does not support streaming; the platform does not guarantee schema compliance in extreme cases.

Note that Workers AI can’t guarantee that the model responds according to the requested JSON Schema.

— Cloudflare, JSON Mode

  • Calling Paid-only IDs (@cf/moonshotai/kimi-k2.6, @cf/moonshotai/kimi-k2.7-code, DeepSeek V4 family, and others) on a Free plan and treating HTTP 403 as an application bug.
  • Expecting prefix cache savings without x-session-affinity (Workers AI) or cf-aig-session-id (Auto Router multi-turn).
  • Putting timestamps in the system prompt, which changes every request and defeats prefix matching.
  • Choosing an embedding model in AI Search that does not match re-indexing needs (dimensions, max tokens, multimodal vs text-only), then trying to change embeddings after creation (not editable).
  • Migrating Kimi K2.5 without updating reasoning request/response field names before the May 30, 2026 alias to K2.6.
  • Using BGE pooling: cls without re-embedding existing vectors.
  • Setting max_tokens without reserving space inside the model context window for the full prompt plus completion.
  1. In the Cloudflare dashboard, open AI → Workers AI, create an API token, and send a test chat completion as in Create your first AI Gateway using Workers AI (include cf-aig-gateway-id when routing through Gateway).
  2. Compare your chosen model ID against Supported models if the workload is AI Search RAG, and confirm embedding vs generation roles in configuration.
  3. Run two sequential requests with the same messages plus a small new user turn; send x-session-affinity (or cf-aig-session-id through Auto Router) and confirm non-zero cached_tokens in usage per Prompt caching.
  4. If a model returns 403 / error 5035, verify Workers Paid or prepaid AI Gateway eligibility per Select models now require the Workers Paid plan and the target model page (for example @cf/deepseek-ai/deepseek-v4-flash-0731).
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page does not match the official docs, email yimasynthetic@gmail.com with the page URL and the exact statement you think is wrong, and we will clarify or correct it.