{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/usdf-fi/json-schema/usdf-fi-chat-completion-request-schema.json",
  "title": "ChatCompletionRequest",
  "description": "A chat completion request: the fields below and the rest of the chat completions format. The deprecated functions and function_call are refused (use tools).",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/usdf-fi-openapi.json#/components/schemas/ChatCompletionRequest",
  "type": "object",
  "properties": {
    "model": {
      "type": "string",
      "description": "A model id from GET /v1/models, in either spelling: the router's author/slug (meta-llama/llama-3.3-70b-instruct) or the catalog id (llama-3.3-70b-instruct). Omitted (with no models list), the request runs on auto where the auto router is on, as the router runs it on the account's default model; required otherwise."
    },
    "models": {
      "type": "array",
      "description": "Models to fall back on, tried in order after model (or, without model, the first of them first; at most 8 in all, each once). The first model that can serve the request serves it: a model with no route for it (not available now, no route for its provider asks or its size, outside the key's, the account's or an agent's model lists, above the price ceiling) is passed over before anything runs, and one whose every route fails before taking the request (a 429, a 500, a 502, a 503, a 504 or a 529, as the answer's status or in the body of an answer with no output; a connection that failed with no answer; a stream whose first event is an error) is passed over as the request runs, nothing billed for it. A provider takes the request when it begins serving it (a stream's first event that is not an error, or an answer sent whole that begins to arrive); a request not streamed whose answer then fails on the way goes to no other route or model, since that provider may bill it: it ends there, refunded. A request the provider refuses as sent is not tried on another model. The request is held once at the most its dearest model can cost (over x402, quoted at it), each model held as its own request would be (a model held for its whole window holds it) and sent its own output budget, charged at the price of the model that served, which the answer's model names, and the rest goes back; receipt.models lists the models passed over and why. A private ask of any of the models is every model's, and a Private-tier key's request runs on attested enclaves only, on every model; over x402, an ERC-8004 agent is held to its model list for every model named, and its owner's approval names them all. Not with the free tier, x-self-route, end-to-end encryption, a batch job or a preset named as a model (@preset/..., whose fields are its own; a request's preset field applies to every model) (400 models_unsupported); the response cache, a compute lock and the marketplace's listings serve requests that name one model (a model only the listings could serve is passed over). With none of the models able to serve it, the request is refused as the last one was, its message naming each model and why.",
      "items": {
        "type": "string"
      }
    },
    "messages": {
      "type": "array",
      "description": "The conversation.",
      "items": {
        "$ref": "#/$defs/ChatMessage"
      },
      "minItems": 1
    },
    "max_tokens": {
      "type": "integer",
      "description": "The most output tokens, any reasoning the model does included, so a small value can leave little or no room for the answer. Left out, the request gets what the model's window leaves after the prompt.",
      "minimum": 1
    },
    "max_completion_tokens": {
      "type": "integer",
      "description": "The same as max_tokens.",
      "minimum": 1
    },
    "temperature": {
      "type": "number",
      "minimum": 0,
      "maximum": 2
    },
    "top_p": {
      "type": "number"
    },
    "stream": {
      "type": "boolean",
      "description": "Answer as server-sent events (text/event-stream), with a `: processing` comment while the stream is quiet, ending with the receipt as an SSE comment and data: [DONE]."
    },
    "stream_options": {
      "type": "object",
      "properties": {
        "include_usage": {
          "type": "boolean",
          "description": "true: usage null on every chunk, then one final chunk with empty choices carrying it. false: no usage. Not sent: the usage rides the last chunk, with its finish."
        }
      }
    },
    "stop": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      ]
    },
    "tools": {
      "type": "array",
      "description": "Function tools the model may call.",
      "items": {
        "type": "object"
      }
    },
    "tool_choice": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "object"
        }
      ]
    },
    "response_format": {
      "type": "object"
    },
    "transforms": {
      "type": "array",
      "description": "[\"middle-out\"]: a prompt that does not fit the model's context window, with the output it asks for, is cut from its middle until it fits (whole messages nearest the middle first, a tool call with its results together; the system messages and the last message stay; then the longest text left, in its middle), before anything is quoted or held, so it is priced and billed on what is sent; marked x-transforms-applied: middle-out and x-middle-out-removed. A prompt that fits is sent untouched. Off unless asked: without it a prompt that does not fit is refused (400 context_length_exceeded). The same as the plugin {\"id\": \"context-compression\", \"engine\": \"middle-out\"}.",
      "items": {
        "type": "string",
        "enum": [
          "middle-out"
        ]
      }
    },
    "plugins": {
      "type": "array",
      "description": "Two plugins are served, at no charge: response-healing ({\"id\": \"response-healing\"}: an answer sent whole to a request in JSON mode, response_format json_object or json_schema, whose text is not valid JSON is repaired where it can be: a code fence, text around the JSON, a trailing comma, an answer cut short with strings or brackets left open; one that parses is never changed, one that cannot be repaired comes as it came, the charge is the same; marked x-response-healed: true; a stream is sent as it arrives) and context-compression (engine middle-out, as transforms). Where web search is on, a third: web ({\"id\": \"web\", \"max_results\": 1-25, default 5, \"search_prompt\", \"include_domains\", \"exclude_domains\", \"mode\"}; the same as a model id ending :online, or web_search_options): one search for the last user message before the model, its results added to that message, charged on its own usage row at the search's cost plus the payer's fee (never free credit; refused 400 web_search_retention where the request asks for zero retention itself or runs privately; a batch job is refused 400 web_search_unsupported); the answer carries message.annotations (url_citation: url, title, content, start_index, end_index; a stream on its last chunk with a choice), usage.server_tool_use_details.web_search_requests and the headers x-web-search-request-id and x-web-search-cost-units; the search's charge is in what the answer says the request cost (x-cost-units and usage.cost are the model's charge plus the search's; the receipt keeps the model's cost beside web_search, the search's request id and cost, and total_cost, the two together; on /v1/chat/completions and /v1/completions only: /v1/responses and /v1/messages give their own usage, without the search). A refusal after a paid search carries no x-cost-units: x-web-search-cost-units and its words say what the search was charged. Any other plugin is refused (400 plugin_unsupported); a plugin named off ({\"enabled\": false}) asks for nothing.",
      "items": {
        "type": "object"
      }
    },
    "seed": {
      "type": "integer"
    },
    "n": {
      "type": "integer",
      "description": "Choices in one answer, 1 to 8, on a model whose routes answer several (otherwise 400 unsupported_parameter, param n, before anything is held). The output budget is held for each choice, and the charge counts the choices the answer carries (receipt.choices). Batch jobs, the free tier and /v1/completions answer one.",
      "minimum": 1,
      "maximum": 8
    },
    "presence_penalty": {
      "type": "number"
    },
    "frequency_penalty": {
      "type": "number"
    },
    "top_a": {
      "type": "number",
      "description": "Sent on to a route that takes it (its supported_parameters name it); ignored by any other.",
      "minimum": 0,
      "maximum": 1
    },
    "verbosity": {
      "type": "string",
      "description": "Sent on to a route that takes it (its supported_parameters name it); ignored by any other.",
      "enum": [
        "low",
        "medium",
        "high"
      ]
    },
    "prediction": {
      "type": "object",
      "description": "Accepted and not sent on: a predicted output is billed in part as output past what the request holds."
    },
    "user": {
      "type": "string"
    },
    "provider": {
      "$ref": "#/$defs/ProviderPreferences"
    },
    "mode": {
      "type": "string",
      "description": "How Dispatch ranks the quotes (a quote: the request's estimated charge at a route's current price): cheapest (the default), the lowest quote; fastest, the highest median output speed over 7 days; efficient, the highest tokens per dollar per watt (the tokens a dollar buys at the route's quote times the tokens each watt-hour yields there: measured on Foundry's own operators, a public per-model figure marked estimated elsewhere; a route with no energy figure after those with one), the same figure settling a tie the other modes leave; smartest, the model with the highest quality score among several in scope (model auto, or a models list), within rules.price_cap (400 smartest_needs_several_models, 400 smartest_needs_price_cap otherwise); auto, the model chosen for the prompt. Also a suffix on the model id, model:fastest, counted only when the word after the colon is a mode name.",
      "enum": [
        "cheapest",
        "fastest",
        "smartest",
        "auto",
        "efficient"
      ]
    },
    "rules": {
      "$ref": "#/$defs/RouterRules"
    },
    "batch": {
      "type": "boolean",
      "description": "Run as a batch job at the batch rate: answered 202 with the job (GET /v1/batches/{id}); not streamed."
    },
    "webhook_url": {
      "type": "string",
      "description": "For a batch job: an https URL that is posted the job when it ends."
    },
    "service_tier": {
      "type": "string",
      "description": "cheapest: routes by price. standard: by price, then speed. priority: the provider's priority processing at its premium list price (400 priority_unavailable where no route of the model has it). flex: the provider's flex processing at the batch rates, or a batch job (202) where the model has a batch API instead (400 flex_unavailable where it has neither). auto and default: the default order.",
      "enum": [
        "cheapest",
        "standard",
        "priority",
        "flex",
        "auto",
        "default"
      ]
    },
    "cache": {
      "type": "boolean",
      "description": "true: answer it from the response cache when an identical request (same model, service tier, output budget and body) was answered within the cache's lifetime, at no charge, and keep its answer for the next one; false or absent: never (a gateway may also answer requests with temperature 0 or a seed from the cache without being asked). Not for a streamed request or one with tools."
    }
  },
  "required": [
    "messages"
  ],
  "$defs": {
    "ChatMessage": {
      "type": "object",
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "system",
            "developer",
            "user",
            "assistant",
            "tool"
          ]
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "type": "object"
              }
            },
            {
              "type": "null"
            }
          ],
          "description": "Text, or an array of content parts (text and image_url)."
        },
        "name": {
          "type": "string"
        },
        "tool_calls": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "tool_call_id": {
          "type": "string"
        }
      },
      "required": [
        "role"
      ]
    },
    "ProviderPreferences": {
      "type": "object",
      "description": "Routing preferences. A request's routing asks override the account's defaults (GET /v1/account/settings) field by field; its privacy asks (zdr, data_collection, private) only add to them. Zero data retention is asked by every request for a model with a route that keeps nothing (the account's zdr, on unless turned off); a model with none is served on its own routes as sent (may_keep_data), and nothing opts in. The account's own provider keys (/v1/byok) serve under that default (the stored key is the account's choice of that provider); the response headers say whether one served (x-byok: used, or not_used with x-byok-reason). A model id suffix asks for some of them too: :cheapest (sort by price), :fastest (by latency), :reliable (by reliability), :private, and :batch (a batch job). The x-price-ceiling, x-route-type and x-fallback headers ask for price_ceiling, route_type and fallback where the object does not; the answer names what was asked and the route that served in its x-router headers and receipt.router.",
      "properties": {
        "zdr": {
          "type": "boolean",
          "description": "true demands zero data retention: only routes that keep no request content, and 409 retention_required, at no cost, for a model (or a batch job) whose every route keeps data. Without it a request asks for zero retention wherever its model has a route that keeps nothing (the default), and a model with no such route (may_keep_data) is served on its own routes as sent; false does not lift the default. There is no opt-in to retention: a provider.allow_retention sent is ignored."
        },
        "data_collection": {
          "type": "string",
          "description": "deny: only routes that do not train on or keep content.",
          "enum": [
            "allow",
            "deny"
          ]
        },
        "private": {
          "type": "boolean",
          "description": "Only attested routes, at the model's private price: the attested (confidential computing) enclaves first, then a network compute node at trust level self_signed (its receipt says private: self_signed)."
        },
        "attested_only": {
          "type": "boolean",
          "description": "Attested enclaves only (asks for private too): never a network compute node, as every request of a Private-tier key."
        },
        "sort": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "price",
                "latency",
                "throughput",
                "reliability"
              ]
            },
            {
              "type": "object",
              "properties": {
                "by": {
                  "anyOf": [
                    {
                      "type": "string",
                      "enum": [
                        "price",
                        "latency",
                        "throughput",
                        "reliability"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "partition": {
                  "anyOf": [
                    {
                      "type": "string",
                      "enum": [
                        "model"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          ],
          "description": "price: the cheapest route first; latency or throughput: the fastest; reliability (the most reliable): the highest recent success rate first, then the highest uptime, then the cheapest (also the :reliable suffix on the model id). Without a sort: the cheapest route in service first, a route failing now after the others. The object form {\"by\": ..., \"partition\": \"model\"} reads as its by (by null: no sort); partition none is refused (400): each model's routes are ordered, fallback models stay fallbacks."
        },
        "route_type": {
          "type": "string",
          "description": "The kind of route that may serve: direct, the model developer's own API; book, a route a registered supplier offers or a marketplace listing (for a request whose routing asks no zero retention); provider, a host's route; any (the default), all of them. Also the x-route-type header.",
          "enum": [
            "direct",
            "book",
            "provider",
            "any"
          ]
        },
        "fallback": {
          "type": "string",
          "description": "off: only the first route the request would try (with order, only the providers it names), no failover (allow_fallbacks: false). Also the x-fallback header.",
          "enum": [
            "on",
            "off"
          ]
        },
        "price_ceiling": {
          "anyOf": [
            {
              "type": "number",
              "description": "USDF per 1M tokens."
            },
            {
              "type": "string",
              "description": "\"2.5\" or \"2.5/1M\" (USDF per 1M tokens), or \"0.05/request\" (USDF for the whole request at its worst case)."
            },
            {
              "type": "object",
              "properties": {
                "per_million": {
                  "type": "number"
                },
                "per_request": {
                  "type": "number"
                }
              }
            }
          ],
          "description": "The most the request may cost: per 1M tokens against every rate it can be billed at, and/or for the whole request at its worst case (its hold). A request above it is refused 402 price_ceiling_exceeded before anything is held. Also the x-price-ceiling header."
        },
        "region": {
          "type": "string",
          "description": "A region code such as us."
        },
        "only": {
          "type": "array",
          "description": "Only these providers: this gateway's ids (GET /v1/pricing names them per route), or their provider_name as GET /v1/models/{author}/{slug}/endpoints gives it, or that name as a slug (lower case, spaces and dots as dashes), read as the ids.",
          "items": {
            "type": "string"
          }
        },
        "ignore": {
          "type": "array",
          "description": "Never these providers, named as in only.",
          "items": {
            "type": "string"
          }
        },
        "allow": {
          "type": "array",
          "description": "The same field as only, by the account settings' name (provider_allow); send one of the two.",
          "items": {
            "type": "string"
          }
        },
        "deny": {
          "type": "array",
          "description": "The same field as ignore, by the account settings' name (provider_deny); send one of the two.",
          "items": {
            "type": "string"
          }
        },
        "order": {
          "type": "array",
          "description": "Providers tried first, in this order, named as in only: their routes go first (each provider's own routes in the request's order), then every other route in the request's order. With allow_fallbacks false, only the providers it names are tried, and a model none of them serves is refused 404 no_route_for_policy at no cost. A private request still tries its attested enclaves before any network compute node, whatever the order names. The answer's router says why ordered where the route that served is first because the order names it.",
          "items": {
            "type": "string"
          }
        },
        "allow_fallbacks": {
          "type": "boolean",
          "description": "Whether another route may serve the request when the first cannot. false: only the first route the request would try, or, with order, only the routes of the providers it names."
        },
        "quantizations": {
          "type": "array",
          "description": "Only routes whose weights run at one of these precisions. A route's precision is the one its source states: a hosted route's, the precisions the source states for the model's endpoints at its best (full precision wherever one runs it), and the source is asked for those within this list; a network compute node's, its weights'; every other route's is unknown (its provider states none here), which only unknown admits. A model with no route left is refused 404 no_route_for_policy, naming each route's precision, at no cost. An empty list asks nothing.",
          "items": {
            "type": "string",
            "enum": [
              "int4",
              "int8",
              "fp4",
              "mxfp4",
              "nvfp4",
              "fp6",
              "fp8",
              "mxfp8",
              "fp16",
              "bf16",
              "fp32",
              "unknown"
            ]
          }
        },
        "max_price": {
          "type": "object",
          "description": "The most the request may be charged per token: input and output (prompt and completion are the same fields by the router's names).",
          "properties": {
            "input": {
              "type": "number",
              "description": "USD per 1M input tokens."
            },
            "output": {
              "type": "number",
              "description": "USD per 1M output tokens."
            },
            "prompt": {
              "type": "number",
              "description": "The same as input; send one of the two."
            },
            "completion": {
              "type": "number",
              "description": "The same as output; send one of the two."
            }
          }
        },
        "preferred_min_throughput": {
          "anyOf": [
            {
              "type": "number",
              "description": "Output tokens a second: the median's cutoff (p50)."
            },
            {
              "type": "object",
              "description": "Cutoffs by percentile, any of them; a provider must meet every one given.",
              "properties": {
                "p50": {
                  "type": "number"
                },
                "p75": {
                  "type": "number"
                },
                "p90": {
                  "type": "number"
                },
                "p99": {
                  "type": "number"
                }
              }
            }
          ],
          "description": "A preference, never a filter: a provider measured slower than this (output tokens a second) at any percentile given is tried after the providers that meet it, and still serves when none of them can. Measured over the last 30 minutes, else the last day; a provider not measured counts as meeting it. Each value above 0 and at most 100000; any other value or key is refused 400."
        },
        "preferred_max_latency": {
          "anyOf": [
            {
              "type": "number",
              "description": "Seconds to the first token: the median's cutoff (p50)."
            },
            {
              "type": "object",
              "description": "Cutoffs by percentile, any of them; a provider must meet every one given.",
              "properties": {
                "p50": {
                  "type": "number"
                },
                "p75": {
                  "type": "number"
                },
                "p90": {
                  "type": "number"
                },
                "p99": {
                  "type": "number"
                }
              }
            }
          ],
          "description": "A preference, never a filter: a provider measured slower than this to its first token (seconds) at any percentile given is tried after the providers that meet it, and still serves when none of them can. Measured over the last 30 minutes, else the last day; a provider not measured counts as meeting it. Each value above 0 and at most 600; any other value or key is refused 400."
        },
        "enforce_distillable_text": {
          "type": "boolean",
          "description": "true: only a model whose published weights' licence lets its outputs be used to train other models (Apache 2.0, MIT and the like). Any other model, a closed one or one whose licence is not known included, is refused 404 distillation_not_allowed before anything is charged, and a models list passes it over. false asks nothing."
        }
      }
    },
    "RouterRules": {
      "type": "object",
      "description": "Dispatch, our real-time routing engine. Every provider competes, the cheapest wins. Its rules for one request (also saved in a preset): every provider that serves the model quotes; only those that meet every rule compete. Zero retention is the default on a model with a route that keeps nothing: zero_retention false lets routes that keep data compete too.",
      "properties": {
        "price_cap": {
          "type": "number",
          "description": "USD: the most the whole request may cost. A request whose worst case is above it is refused 402 price_ceiling_exceeded before anything is held."
        },
        "max_ttft_ms": {
          "type": "integer",
          "description": "The most time to the first output, ms. A provider measured slower is tried after the others; a stream whose provider has not begun answering in time moves to the next one.",
          "minimum": 100,
          "maximum": 600000
        },
        "min_tps": {
          "type": "integer",
          "description": "The least output speed, tokens a second. A provider measured slower is tried after the others.",
          "minimum": 1,
          "maximum": 10000
        },
        "region": {
          "type": "string",
          "description": "Only providers that process in this region, such as us or eu."
        },
        "zero_retention": {
          "type": "boolean",
          "description": "true: only providers that keep nothing of the request."
        },
        "no_training": {
          "type": "boolean",
          "description": "true: only providers that never train on requests."
        },
        "providers": {
          "type": "object",
          "description": "Providers that may, or may not, quote: ids as GET /v1/pricing names them, or kind:hosted, kind:network, kind:private.",
          "properties": {
            "allow": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "deny": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "models": {
          "type": "object",
          "description": "Models that may, or may not, serve; * matches any text. For mode auto, the models Auto chooses among.",
          "properties": {
            "allow": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "deny": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "cost_tier": {
          "type": "string",
          "description": "For mode auto and smartest: doubling the price must buy 5 (economy), 2 (balanced) or 0.5 (premium) more quality points.",
          "enum": [
            "economy",
            "balanced",
            "premium"
          ]
        }
      }
    }
  }
}