response_format. Messages uses output_config.format. Strict function tools are a separate feature: they shape a function’s arguments rather than the assistant’s text answer.
Before you start
Create an API key in the dashboard withchat:completions for Chat Completions or messages:create for Messages. If your key has a model allowlist, include lume-3.5. Keep the key on your server and set it in the shell where you run the examples:
Authorization: Bearer or x-api-key. Supplying both with values returns HTTP 401.
For SDK examples, install the client you use. cURL examples do not need an SDK.
.py file. Save Node.js examples as .mjs files to use import and top-level await.
Messages accepts an optional anthropic-version header. If supplied, it must be one valid calendar date in YYYY-MM-DD form. It is a compatibility hint and does not change the supported features. The SDK supplies its version header automatically.
Chat Completions
CallPOST /v1/chat/completions with chat:completions. Set response_format.type to json_schema and supply a named schema. This example extracts an event from the supplied sentence.
choices[0].message.content. An illustrative answer is {"name":"Launch","city":"Milan"}. The examples check that the reply completed, parse it, and validate this small schema’s fields. For a larger schema, use a JSON Schema validator in your application.
For JSON without a supplied schema, Chat also accepts response_format: {"type":"json_object"}. Include an instruction to return JSON in the message. This selects JSON output without defining your application’s fields or types. Omit response_format, or use {"type":"text"}, for ordinary text.
Messages
CallPOST /v1/messages with messages:create. Supply output_config.format with type: "json_schema" and a schema object. Do not send the Chat response_format wrapper or its json_schema.name field on Messages.
content. Read those blocks rather than assuming the first block is text. Messages supports the schema format shown here; it does not expose Chat’s json_object option. You can combine output_config.format and output_config.effort in the same request.
Schema and output limits
Use a JSON object for the schema. Oversized or excessively nested schemas are rejected. An unsupported format or a malformed format object returns HTTP 400. Keep your schema focused on the fields the application needs.
strict: true requests strict schema handling on Chat. Your application should still check for truncation, parse the JSON, and validate the result before using it.
Lume 2 allows up to 16,384 output tokens; the other models allow up to 32,768. Both APIs reduce the output budget to the model maximum and remaining context space. Messages requires max_tokens; Chat accepts one of max_tokens and max_completion_tokens, defaulting to the model maximum if omitted.
Chat finish_reason: "length" or Messages stop_reason: "max_tokens" means the JSON can be incomplete. Do not parse individual streaming fragments as complete JSON; assemble the text and check completion first. Handle parse and schema-validation failures in your application.
Usage and errors
Structured output uses normal model token pricing. Readusage in the response and see Pricing for rates. Setting a format does not remove token costs. Requests reserve estimated usage before running and release unused reserved usage afterward.
HTTP 401 indicates invalid authentication, HTTP 403 can indicate missing endpoint permission, and HTTP 429 with Insufficient credits means available usage cannot cover the reservation. Check model permissions too; Messages returns HTTP 404 for unknown or disallowed models. Keep X-Request-Id for support; Messages also returns request-id.
Next
Function calling
Shape function arguments and execute a tool in your application.
Reasoning
Choose the effort used to produce an answer.

