Structured outputs
Request a predictable JSON shape for results your application will process.
Choose a schema-capable route
Use response_format.type: json_schema with a named json_schema object. A model must publish structured_outputs support. JSON object mode only requests JSON; it does not enforce your application's field schema.
Define a small output shape
The example requires a single string field and rejects extra properties. Keep the schema within the provider's supported JSON Schema subset and use provider.require_parameters: true when the format is essential.
curl
curl --request POST \
--url 'https://api.tokenlane.de/v1/chat/completions' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"model": "deepseek/deepseek-v4-flash-0731",
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"max_tokens": 400,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "answer",
"strict": true,
"schema": {
"type": "object",
"properties": {
"answer": {
"type": "string"
}
},
"required": [
"answer"
],
"additionalProperties": false
}
}
},
"provider": {
"require_parameters": true
}
}'
node
import OpenAI from 'openai';
const client = new OpenAI({ baseURL: "https://api.tokenlane.de/v1", apiKey: process.env.TOKENLANE_API_KEY });
const response = await client.chat.completions.create({
"model": "deepseek/deepseek-v4-flash-0731",
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"max_tokens": 400,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "answer",
"strict": true,
"schema": {
"type": "object",
"properties": {
"answer": {
"type": "string"
}
},
"required": [
"answer"
],
"additionalProperties": false
}
}
},
"provider": {
"require_parameters": true
}
}, {});
console.log(response);
python
import os
import json
from openai import OpenAI
client = OpenAI(base_url="https://api.tokenlane.de/v1", api_key=os.environ["TOKENLANE_API_KEY"])
body = json.loads(r'''{
"model": "deepseek/deepseek-v4-flash-0731",
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"max_tokens": 400,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "answer",
"strict": true,
"schema": {
"type": "object",
"properties": {
"answer": {
"type": "string"
}
},
"required": [
"answer"
],
"additionalProperties": false
}
}
},
"provider": {
"require_parameters": true
}
}''')
response = client.chat.completions.create(
model=body["model"],
messages=body["messages"],
max_tokens=body["max_tokens"],
response_format=body["response_format"],
extra_body=json.loads(r'''{
"provider": {
"require_parameters": true
}
}''')
)
print(response)
vercel
// This operation uses HTTP directly.
const response = await fetch("https://api.tokenlane.de/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer " + process.env.TOKENLANE_API_KEY,
"Content-Type": "application/json",
},
body: `{
"model": "deepseek/deepseek-v4-flash-0731",
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"max_tokens": 400,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "answer",
"strict": true,
"schema": {
"type": "object",
"properties": {
"answer": {
"type": "string"
}
},
"required": [
"answer"
],
"additionalProperties": false
}
}
},
"provider": {
"require_parameters": true
}
}`,
});
console.log(await response.text());
Validate the answer
Parse the content and validate it against your schema before using it. Check truncation, refusal and errors first. A schema-valid string is still untrusted content and can be factually wrong. Lower output limits can cut off JSON; leave room for the complete object.
Fix format failures
Simplify unsupported schema constructs or choose a compatible route. JSON healing can repair syntax on non-streaming requests, but it does not validate your schema or make incorrect content correct. Do not retry indefinitely after the same unsupported-schema error.