OPTINROUTER / DEVELOPER DOCS

Grammar definition & enforcement

A grammar is a versioned output contract. It defines allowed structure independently of whether a response sounds plausible.

Contract preview · Production API access is closed. All /v1 endpoints currently return 401.Install CLI
01

Supported preview format

The first design targets a bounded JSON Schema subset. The example uses object properties, required fields, primitive types and size limits. Arbitrary executable validators, remote reference loading, recursive schemas and EBNF are not enabled by this preview. Future formats need explicit certification.

02

Define a response grammar

This contract requires a summary and boolean approval. It rejects additional fields. Grammar definitions are configuration written by an authorized administrator, not rules supplied by untrusted model output.

json
{
  "version": "2026-10-19-preview",
  "name": "Review result",
  "format": "json_schema",
  "target": "response",
  "definition": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
      "summary": {
        "type": "string",
        "maxLength": 2000
      },
      "approved": {
        "type": "boolean"
      }
    },
    "required": [
      "summary",
      "approved"
    ]
  },
  "max_bytes": 8192,
  "max_depth": 4,
  "on_invalid": "block"
}
03

Valid and invalid output

The first object matches the grammar. The second fails because approved must be a boolean and extra fields are forbidden. Validation errors identify the path and rule without echoing confidential content.

json
{"summary":"The example is well structured.","approved":true}

// Invalid example
{"summary":"Reviewed","approved":"yes","execute_shell":"..."}
04

Enforcement and repair

Validate request envelopes, tool arguments and model responses under separate target grammars. Bound bytes, nesting, deadlines and any repair attempts. Repairs consume inference budget. Invalid results block or enter an explicit hold; validation failure never disables the rule.

05

Buffered and streaming delivery

Buffered mode validates the entire protected unit before release. Streaming requires certified incremental validators and clear release units. Whole-response semantic or grammar checks can require buffering. Bytes already delivered cannot be recalled, and stopping a later stream does not undo earlier disclosure.

Contracts & examples

Download the preview, validate its shape locally and review the capability limits before planning an integration.

OpenAPI preview

OptinRouter AI guide

Product and developer guidance.

A good place to start

What would you
like to know?

Ask about public APIs, policies, grammars, context actions or the product. This guide uses approved information and can’t reveal private details or take actions.

Recent messages stay in this page’s memory. Reload or reset to clear them here.