Structured generation
Ask a model of your workspace's catalogue for an object that satisfies your own JSON Schema, journaled and charged like every AI call.
POST /ai/generate/object runs one generation for your own code: you give a prompt, a JSON Schema and, optionally, a model of the workspace's catalogue; Standards answers with an object that satisfies the schema. A classifier, a judge or an extractor needs no model key and no AI SDK of its own, and what it spends shows in the workspace's usage.
The request
curl -X POST "https://api.standards.new/v1/ai/generate/object" \
-H "Authorization: Bearer stndrds_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-haiku-5.5",
"system": "Say whether the document is a bank account statement.",
"prompt": "IBAN FR76 3000 6000 0112 3456 7890 189 …",
"schema": {
"type": "object",
"properties": { "isStatement": { "type": "boolean" }, "reason": { "type": "string" } },
"required": ["isStatement", "reason"]
}
}'| Field | Description |
|---|---|
prompt | What the model answers. Required. |
schema | The JSON Schema the object must satisfy. Required. A $ref is read when it is # or #/$defs/<name> naming an entry of the root's $defs (#/definitions/<name> under draft-07 and draft-04), recursion included when it goes through a property or an item; a recursion that applies itself more than once to the same value (two of its $refs in one allOf, anyOf or oneOf, or beside each other in one schema) is refused, since an answer would cost a check per path through the copies, but a binary tree (left and right both { "$ref": "#" }) is read; any other $ref (external, or spelled otherwise), or one that loops back to itself without descending ({ "$ref": "#" }), is refused. pattern and patternProperties are refused: describe a format in the prompt instead. At most 64 levels deep and 1,000 objects and arrays, counted both as written and with each $ref read in place. |
system | Instructions sent as the system message. |
model | A model id of the workspace's catalogue, with or without its provider prefix. Omitted, the workspace's utility model answers. Either runs at its lowest reasoning effort. |
The answer is 201:
{
"object": { "isStatement": false, "reason": "A transfer order, with a bank detail attached." },
"model": "claude-haiku-5.5",
"usage": { "inputTokens": 412, "outputTokens": 38 }
}model is the catalogue id of the model that answered. An answer the schema refuses is asked again with the reason, at most twice, and usage sums every attempt. An answer nested deeper than 64 levels is refused the same way, before the schema checks it.
Refusals
| Status | Code | When |
|---|---|---|
400 | AI_INVALID_MODEL | model is not in the workspace's catalogue. |
400 | AI_MODEL_DISABLED | model is one the workspace disabled (disabled models). |
400 | SCHEMA_VALIDATION_FAILED | schema is not a JSON Schema Standards reads, uses a refused keyword, or exceeds its bounds. |
402 | CREDITS_EXHAUSTED | The workspace has no credits left for the call. |
403 | SCHEMA_FORBIDDEN | The caller lacks agents:read. |
500 | AI_GENERATION_FAILED | The model never produced a valid object, or stopped at its output cap. |
The 400 refusals are answered before any model is called, so they cost nothing.
From the SDK
import { createStandards } from "@standards/client";
import * as z from "zod";
const standards = createStandards();
const verdict = z.strictObject({ isStatement: z.boolean(), reason: z.string() });
const { object } = await standards.ai.generateObject({
model: "anthropic/claude-haiku-5.5",
prompt: documentText,
schema: z.toJSONSchema(verdict),
});
const { isStatement } = verdict.parse(object);object arrives as unknown: parse it with the schema you sent to get its type.
Charged like a chat turn
The call is written to the AI journal before it runs and priced when the AI Gateway reports its cost, as every generation is. It needs agents:read, the grant that lets a member spend the workspace's AI by chatting with an agent.
Next steps
- Usage and limits: read what the generations cost.
- Roles and permissions: the
agentscapability this route checks. - Book a demo
Machines and links
Every conversation and routine run works on a machine; runs about one pull request share one, and anything a machine serves opens for your members at a standards.run link.
Conversation evals
Judge every finished conversation of a routine, an agent or a folder against a list of criteria, and read the pass rates in the Routines page's Evaluations view.