multi-router.aidocs

Prompts

Prompt Variables

Placeholders in a prompt that each request fills in with its own values.

A variable is a named placeholder in a prompt, written in double curly braces as {{customer_name}}, that each request fills in with its own value. Variables let one prompt serve every request that differs only in a few details, such as the customer, product, plan or language, while the prompt itself stays in one place. Multi-Router lists the variables of every prompt on its page and in the API's variables field.

Syntax

A variable is a name between {{ and }}. A name starts with a letter or underscore, continues with letters, digits and underscores, and is case sensitive. Spaces inside the braces are allowed, so {{ product }} and {{product}} are the same variable. A variable used several times in a prompt takes the same value everywhere.

Written in the promptResult
{{product}}The variable product.
{{ product }}The variable product.
{{customer_name}}The variable customer_name.
{{_region2}}The variable _region2.
{{2nd_item}}Kept as written. A name cannot start with a digit.
{{order-id}}Kept as written. A name cannot contain a hyphen.
{{ product }Kept as written. The braces are not balanced.

Text that is not a valid variable stays in the prompt exactly as written, which lets a prompt include literal double braces, such as a template example, by writing them in a form that is not a valid name.

Supplying values

A request supplies variable values in the top-level prompt_variables object, which maps each variable name to a string. The field is accepted on Chat Completions and on Messages:

Chat Completionsbash
curl https://api.multi-router.ai/v1/chat/completions \
  -H "Authorization: Bearer $MR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "multi-router/rt_9Hk3Ws7PzQ",
    "messages": [{ "role": "user", "content": "How do I reset my password?" }],
    "prompt_variables": { "product": "Acme Cloud", "language": "Spanish" }
  }'
Messagesbash
curl https://api.multi-router.ai/v1/messages \
  -H "Authorization: Bearer $MR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "multi-router/rt_9Hk3Ws7PzQ",
    "max_tokens": 1024,
    "messages": [{ "role": "user", "content": "How do I reset my password?" }],
    "prompt_variables": { "product": "Acme Cloud", "language": "Spanish" }
  }'

Every value is a string; a number or boolean makes the request invalid. The values follow these rules:

CaseBehavior
A value for every variableEach placeholder is replaced with its value.
A variable with no valueThe request is rejected with missing_prompt_variables.
An empty stringAccepted. The placeholder is replaced with nothing.
A name the prompt does not useIgnored.
A value containing double bracesInserted as written. Values are not scanned for further variables.
No prompt bound to the routerprompt_variables is ignored.

Variables in chat prompts

In a chat prompt, variables are filled in throughout each message: in its content, including every text part, and in the message's name and tool call fields when the prompt includes them. One prompt_variables object supplies the values for every message in the prompt.

Missing variables

A request that omits a variable the bound prompt uses is rejected before it reaches the provider, with status 400 and the error missing_prompt_variables. The message lists every missing variable. For a chat prompt, each name is shown with the message it appears in, written as message[index:role].field:name:

Response 400json
{
  "error": {
    "type": "invalid_request_error",
    "code": "missing_prompt_variables",
    "message": "router's bound prompt requires these variables that the request omits: language"
  }
}

On Messages, the error has the Anthropic error shape, with the type invalid_request_error, the code missing_prompt_variables and the same message.

A router that tracks the latest revision uses the variables of whatever revision is current, so adding a variable to a prompt requires every caller to send it. To roll out a new variable safely, update the callers to send it first, since extra values are ignored, and then save the revision that uses it.

Prompt TypePrompt Binding
Was this helpful?