Skip to content
Last updated May 15, 2026

Typed Input Variables

AI Gateway endpoints can declare an ordered list of typed input variables. When set, the gateway:

  1. Expects the request body to be a JSON object whose keys match the schema.
  2. Rejects unknown keys (422).
  3. Coerces values to the declared types and checks constraints.
  4. Substitutes the validated values into {{name}} placeholders in both the system prompt and the user-prompt template.
  5. Sends the rendered template as the user message to the upstream provider — the raw JSON payload never leaves the gateway.

If no variables are declared, the legacy {{input}} flow is used (the raw user message is substituted into a single {{input}} placeholder).

Pick typed variables when:

  • You want clients to send structured data, not a free-form string.
  • You want to reject malformed input at the gateway boundary (before billing the provider).
  • The prompt template references multiple distinct values (name, age, locale, tone, …) and you want each one validated independently.

Keep {{input}} when you only need a single freeform user message.

In the endpoint wizard, Tab 06 — Prompt, click + Add variable.

Each variable has:

FieldRequiredNotes
NameyesMust match ^[a-zA-Z_][a-zA-Z0-9_]*$. Used as {{name}} in templates.
TypeyesOne of string, text, int, float, bool, date, enum.
Requiredno (default true)false makes the variable optional.
Max lengthstring / text onlyReject if mb_strlen exceeds this.
Patternstring / text onlyPCRE regex — the value must match.
Min / Maxint / float onlyInclusive numeric bounds.
Allowed valuesenum onlyComma-separated list.
DescriptionnoUI hint, never sent to the model.

Below the table, the system prompt and user-prompt template each get a chip-row of declared variables. Click a chip to insert {{name}} at the cursor.

TypeAcceptsCoerced to
string / textstring, int, floatstring
intint, numeric stringint
floatint, float, numeric stringfloat
boolbool, "true"/"false", "1"/"0", "yes"/"no", "on"/"off"bool
dateISO-8601 (YYYY-MM-DD or full timestamp)string (passed through)
enumstring matching one of allowedstring

With this schema:

[
{"name": "name", "type": "string", "max_length": 30},
{"name": "age", "type": "int", "min": 0, "max": 150},
{"name": "tone", "type": "enum", "enum": ["formal", "casual"]}
]

Clients POST:

Terminal window
curl -X POST https://gateway.example.com/api/{project_uuid}/v1/chat/completions \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "your-endpoint",
"messages": [
{"role": "user", "content": "{\"name\":\"Ada\",\"age\":30,\"tone\":\"formal\"}"}
]
}'

(The content of the last user message must be the JSON-encoded variables object.)

With prompt:

Persona: {{tone}}

And user_prompt_template:

Greet {{name}}, who is {{age}} years old.

After substitution, the provider sees:

[
{"role": "system", "content": "Persona: formal"},
{"role": "user", "content": "Greet Ada, who is 30 years old."}
]
CauseMessage
Payload is not a JSON objectVariables payload must be a JSON object.
Required value missingMissing required variable: name.
Unknown keyUnknown variable not allowed by endpoint schema: evil.
Type mismatchage must be an integer.
Length violationname exceeds max_length of 30.
Range violationage is above max (150).
Enum violationtone must be one of: formal, casual.
Bad datebirthdate must be an ISO-8601 date (YYYY-MM-DD or full timestamp).

All errors include the variable name; values are never echoed back, so a secret accidentally posted in the wrong field won’t leak via the error log.

Typed variables and the raw input_schema (JSON-Schema) field are independent: when both are set on the same endpoint, typed variables take precedence and the JSON-Schema validator is skipped. New endpoints should prefer typed variables; raw JSON-Schema remains supported for advanced cases that need the full Draft-7 vocabulary.

Was this page helpful?