response_format field on POST /v1/chat/completions controls the shape of the model’s output. Use it to get back machine-readable JSON instead of free-form prose — ideal for data extraction, classification, and tool-style workflows.
Not every model enforces
response_format. It only takes effect on models that support structured output. On many models that don’t, the request still succeeds and returns ordinary text; on others (DeepSeek, Arcee and ILMU, which implement only json_object) a json_schema request is rejected with a 4xx. So if you get prose or an error back instead of the JSON you asked for, the model most likely doesn’t support structured output: check its support on the Models page in your dashboard (app.meshapi.ai → Models, i.e. https://app.meshapi.ai/org/<your-org-id>/models) or the supports_structured_output flag returned by GET /v1/models, and switch to one with first-class support such as OpenAI models or Google Gemini (e.g. google/gemini-2.5-flash). See Not getting JSON back? and How it works across providers.Output modes
response_format is an object whose type selects the mode:
In every mode the JSON is returned as a string in
choices[0].message.content, which you parse client-side.
Schema-enforced output (json_schema)
Supply a json_schema object containing a name (a label) and a schema (the JSON Schema to enforce):
- curl
- Python SDK
- Node.js SDK
Valid JSON without a schema (json_object)
When you only need parseable JSON and don’t want to define a schema, use json_object and describe the keys you expect in the prompt:
json_schema when you need that guarantee.
How it works across providers
response_format follows the OpenAI convention and is forwarded to the upstream provider. For providers with a different native contract, MeshAPI translates it automatically:
- Google Gemini on Vertex AI: converted to Gemini’s native structured-output config (
responseMimeTypeforjson_object, plusresponseSchemaforjson_schema), so schema enforcement runs on the provider side. - Amazon Bedrock (including Anthropic Claude models served there):
json_schemais converted to Bedrock’s native structured-output config. Bedrock can’t combine it with tool use, so on a request that also carriestools,response_formatis dropped.json_objecthas no Bedrock equivalent, so describe the JSON in your prompt. - DeepSeek, Arcee, ILMU:
json_objectonly;json_schemais rejected upstream with a4xx.
response_format. Elsewhere a model may return ordinary text or reject the request.
Tips
- Set
additionalProperties: falsein your schema to forbid extra fields. - Use
temperature: 0for the most deterministic, schema-faithful output. - The content is a JSON string — parse it with
json.loads()/JSON.parse(). - On success
finish_reasonis"stop".
Not getting JSON back?
If the response comes back as ordinary prose instead of the JSON you asked for, the model you chose doesn’t support structured output, or (on Bedrock) the request also carriedtools. response_format is forwarded to the provider, but a provider that ignores it returns plain text. The request still succeeds with finish_reason: "stop", so this fails silently rather than erroring.