JSON healing

Repair common JSON syntax problems without mistaking repair for schema validation.

Use it with JSON output

Add plugins: [{"id":"response-healing"}] and set response_format to json_object or json_schema. The route must support that response format. The plugin applies to non-streaming answers; it leaves streams unchanged to avoid buffering.

Ask for one small object

The example requests JSON explicitly and enables healing. Keep the requested structure clear and allow enough output tokens for a complete result.

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": "Return a JSON object with one key named answer."
    }
  ],
  "max_tokens": 400,
  "response_format": {
    "type": "json_object"
  },
  "plugins": [
    {
      "id": "response-healing"
    }
  ],
  "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": "Return a JSON object with one key named answer."
    }
  ],
  "max_tokens": 400,
  "response_format": {
    "type": "json_object"
  },
  "plugins": [
    {
      "id": "response-healing"
    }
  ],
  "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": "Return a JSON object with one key named answer."
    }
  ],
  "max_tokens": 400,
  "response_format": {
    "type": "json_object"
  },
  "plugins": [
    {
      "id": "response-healing"
    }
  ],
  "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'''{
  "plugins": [
    {
      "id": "response-healing"
    }
  ],
  "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": "Return a JSON object with one key named answer."
    }
  ],
  "max_tokens": 400,
  "response_format": {
    "type": "json_object"
  },
  "plugins": [
    {
      "id": "response-healing"
    }
  ],
  "provider": {
    "require_parameters": true
  }
}`,
});
console.log(await response.text());

Know what repair does

The gateway can remove code fences and surrounding text, fix common comma problems and complete some truncated JSON. Valid JSON stays unchanged. Unrepairable content is returned unchanged. The plugin neither verifies your schema nor corrects facts, permissions or business rules.

Validate before using

Always parse and validate the returned object. If parsing fails, inspect truncation and choose a bounded retry or an explicit application error. Set enabled: false to disable this plugin. For stricter output shapes, use Structured outputs.