Menu: Variables and templates

API builder

Variables and templates

Declare typed inputs and insert them into the system prompt and prompt with {{variables}}.

Variables

Each variable is an input callers send in inputs:

{
  "key": "ticket",
  "label": "Ticket",
  "description": "The ticket to classify.",
  "type": "object",
  "required": true,
  "default": null,
  "enum": null,
  "items": null,
  "properties": [
    { "key": "subject", "label": "Subject", "type": "string", "required": true },
    { "key": "body", "label": "Body", "type": "string", "required": true }
  ]
}
  • key: a lowercase letter, then letters, digits or _, up to 64 characters. Unique among its siblings.
  • type: string, number, integer, boolean, enum, array, object or file.
  • required: callers must send it, unless it has a default.
  • default: used when the variable isn't required and isn't sent.
  • enum: the allowed values, for type enum.
  • items: for type array, a variable-like schema of each item (no key). Items can be objects with their own properties.
  • properties: for type object, a list of variables. Objects nest to any depth.

file variables take {"file_ids": ["<uuid>", ...], "query": "..."}. They're accepted and validated, but running endpoints that use them isn't available yet: the gateway answers 501 not_implemented.

Input validation

The gateway checks inputs before calling a model:

  • every required variable is present unless it has a default;
  • types match: an integer is a whole number, an enum value is listed, objects and array items are checked recursively;
  • inputs that aren't declared are refused.

Problems come back as 422 invalid_inputs with the path:

{ "error": { "message": "inputs.ticket.subject: required", "type": "invalid_inputs", "code": "invalid_inputs" } }

Templates

system and prompt are templates. {{ name }} inserts a variable and {{ obj.field }} reaches into objects. Whitespace inside the braces is ignored.

Classify this ticket and answer in {{ language }}.

Subject: {{ticket.subject}}
Body:
{{ticket.body}}

Values are inserted like this:

ValueInserted as
stringas it is, in any language, nothing stripped
number, booleanJSON (4.5, true)
array, objectcompact JSON (["a","b"])

A name that isn't declared is an error when you save the endpoint and when it runs. There's no other template logic: no conditions or loops. Put that logic in the prompt's wording, or send pre-formatted text as a string variable.

In the console's prompt editors, type {{ or / to pick from the declared variables, including nested object paths.