Text Generation Parameters: Prompt, Sampling, Stream, and Response Format
What Cloudflare Workers AI accepts on each inference request: required prompt, LoRA, raw mode, streaming, max_tokens, sampling limits, and structured JSON output.
This page summarizes Cloudflare Workers AI model reference pages for text and multimodal generation. Individual models share most of the same request fields; larger chat-oriented models also document synchronous, streaming, and batch shapes with messages, tools, and chat-style responses. Check the page for the exact model you call—defaults and allowed ranges are not identical everywhere.
prompt: required input for text generation
Section titled “prompt: required input for text generation”Every documented text path starts with prompt: a non-empty string that is the input the model should answer.
The input text prompt for the model to generate a response.
— Cloudflare, llama-3.1-8b-instruct-fp8
On llama-3.2-11b-vision-instruct, prompt may be up to 131072 characters. Vision and batch chat flows can instead send a messages array (roles such as user, assistant, system, tool) as described on gemma-sea-lion-v4-27b-it and llama-4-scout-17b-16e-instruct.
lora: optional fine-tuned adapter name
Section titled “lora: optional fine-tuned adapter name”lora names a LoRA (Low-Rank Adaptation) adapter applied on top of the base weights.
Name of the LoRA (Low-Rank Adaptation) model to fine-tune the base model.
— Cloudflare, gemma-2b-it-lora
Use it only when your account has a compatible adapter for that base model; omit it for stock models.
raw and stream: formatting and delivery mode
Section titled “raw and stream: formatting and delivery mode”raw: skip the chat template
Section titled “raw: skip the chat template”By default, Workers AI applies each model’s chat template. Set raw to true when you supply prompts already formatted the way the base model expects.
If true, a chat template is not applied and you must adhere to the specific model’s expected formatting.
— Cloudflare, deepseek-r1-distill-qwen-32b
stream: incremental output with SSE
Section titled “stream: incremental output with SSE”With stream: true, the platform returns the completion incrementally using Server-Sent Events (SSE).
If true, the response will be streamed back incrementally using SSE, Server Sent Events.
— Cloudflare, mistral-7b-instruct-v0.2-lora
On models that document a streaming section (for example qwen3-30b-a3b-fp8), streaming responses use contentType text/event-stream and format binary.
max_tokens and sampling parameters
Section titled “max_tokens and sampling parameters”max_tokens: output length cap
Section titled “max_tokens: output length cap”max_tokens limits how many tokens the model may generate in one response. Many models default to 256; gemma-sea-lion-v4-27b-it and qwen3-30b-a3b-fp8 default synchronous max_tokens to 2000. llava-1.5-7b-hf defaults to 512.
The maximum number of tokens to generate in the response.
— Cloudflare, llama-3.2-3b-instruct
temperature, top_p, and top_k
Section titled “temperature, top_p, and top_k”These fields control randomness and how many token candidates the decoder considers:
| Parameter | Typical default | Documented range (most text models) | Effect |
|---|---|---|---|
temperature |
0.6; 0.15 on llama-4-scout-17b-16e-instruct, mistral-small-3.1-24b-instruct, qwq-32b |
0–5 |
Higher values produce more random results. |
top_p |
(no default on some pages) | 0.001–1 on many models; 0–2 on llama-3.2-11b-vision-instruct and several others |
Fewer considered words → more predictable output. |
top_k |
(no default on some pages) | 1–50 |
Lower k → more focused wording. |
Controls the randomness of the output; higher values produce more random results.
— Cloudflare, granite-4.0-h-micro
Adjusts the creativity of the AI’s responses by controlling how many possible words it considers. Lower values make outputs more predictable; higher values allow for more varied and creative responses.
— Cloudflare, qwen2.5-coder-32b-instruct
For deterministic runs where the schema allows it, set seed (integer from 1 to 9999999999) for reproducibility.
repetition_penalty, frequency_penalty, and presence_penalty
Section titled “repetition_penalty, frequency_penalty, and presence_penalty”| Parameter | Typical range on full schemas | Purpose |
|---|---|---|
repetition_penalty |
0–2 |
Higher values discourage repeated tokens. |
frequency_penalty |
-2–2 on many models; 0–2 on some vision and scout-family pages |
Reduces verbatim line repetition. |
presence_penalty |
Same as frequency | Encourages new topics. |
On the web, Chrome’s Prompt API exposes related ideas through samplingMode in the browser and legacy topK / temperature in extensions—not the same API as Workers AI, but the same trade-off between predictable and varied output.
response_format and guided_json: structured output
Section titled “response_format and guided_json: structured output”Many models accept response_format with type either json_object or json_schema, plus json_schema when you need a schema-driven shape. Examples appear on llama-2-7b-chat-hf-lora and deepseek-r1-distill-qwen-32b.
Some models expose guided_json instead of or alongside response_format:
JSON schema that should be fulfilled for the response.
— Cloudflare, mistral-small-3.1-24b-instruct
llama-4-scout-17b-16e-instruct documents both guided_json and response_format on synchronous, streaming, and batch paths.
If you validate outbound JSON elsewhere with Cloudflare API Shield Schema validation, note that validated string formats include date-time, email, uuid, uri, and numeric types such as int32 and double; uniqueItems is documented as not validated by Schema validation. That is separate from Workers AI inference but relevant when you enforce the same schema at the edge after generation.
Response shapes: plain text, chat completions, and tools
Section titled “Response shapes: plain text, chat completions, and tools”Not every model page lists the same response envelope.
| Pattern | Where documented | What you get |
|---|---|---|
| Plain generated text | llama-3.3-70b-instruct-fp8-fast | response string plus usage and optional tool_calls. |
| OpenAI-style chat completion | gemma-sea-lion-v4-27b-it, qwen3-30b-a3b-fp8 | object: chat.completion, choices[].message with content, optional reasoning_content, tool_calls, usage. |
| Vision description | llava-1.5-7b-hf | description string after image + prompt. |
Batch APIs accept a requests array mixing prompt-style and message-style entries on gemma-sea-lion-v4-27b-it; llama-3.3-70b-instruct-fp8-fast batch items may include external_reference for correlating responses.
Image and multimodal inputs
Section titled “Image and multimodal inputs”llama-3.2-11b-vision-instruct: legacy top-level image
Section titled “llama-3.2-11b-vision-instruct: legacy top-level image”This model documents a top-level image field (integer array or binary string) marked deprecated in favor of images inside messages.
Deprecated, use image as a part of messages now.
— Cloudflare, llama-3.2-11b-vision-instruct
llama-4-scout and llava: how to attach images
Section titled “llama-4-scout and llava: how to attach images”llama-4-scout-17b-16e-instruct batch messages content may include image_url.url as a data URI (^data:*); HTTP image URLs are not accepted.
llava-1.5-7b-hf expects image (byte array or binary string) together with prompt and returns a description.
Common mistakes when tuning requests
Section titled “Common mistakes when tuning requests”- Setting
raw: truewithout using the model’s native prompt format, which produces garbled or empty completions. - Assuming
max_tokensdefault 256 on every model while calling qwen3-30b-a3b-fp8 or gemma-sea-lion-v4-27b-it with an implicit 2000-token ceiling. - Passing
top_por penalty values outside the range shown on that model’s page (for exampletop_pminimum0.001vs0depending on model). - Using HTTP image URLs where only
data:URIs are allowed on llama-4-scout-17b-16e-instruct. - Enabling
stream: truebut parsing the body as a single JSON object instead of SSE (text/event-stream). - Requesting JSON via
response_formatorguided_jsonwithout instructions in the prompt that match the schema.
How to check this on your site
Section titled “How to check this on your site”-
Open the Workers AI reference for your model (for example llama-3.1-8b-instruct-fp8) and note defaults for
max_tokens,temperature, and penalty ranges. -
Send a minimal request with only
promptand compare the response shape (plainresponsevschoices[].message) to the synchronous section on qwen3-30b-a3b-fp8 or llama-3.3-70b-instruct-fp8-fast as appropriate. -
Repeat the same prompt with fixed
seedand withstream: falsevsstream: true, confirming streaming uses event-stream semantics per gemma-sea-lion-v4-27b-it. -
If you use structured output, validate a sample against your schema and, for edge validation, cross-check supported formats on Schema validation.
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page does not match the Cloudflare Workers AI docs or your live API behavior, email yimasynthetic@gmail.com with the page URL and the exact sentence you think is wrong.