Repair malformed JSON in a model's answer before it reaches you.
The Response Healing plugin repairs a model's JSON answer when it comes back malformed — a missing bracket, a trailing comma, unquoted keys, JSON wrapped in a Markdown block or surrounded by text — so your JSON.parse gets JSON.
On a request that does not stream, that sets response_format to json_schema or json_object, and that names the plugin:
curl https://opendunes.com/v1/chat/completions \
-H "Authorization: Bearer $OPENDUNES_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-haiku-4.5",
"messages": [{ "role": "user", "content": "A product listing for a 2 kg bag of Deglet Nour dates: name, price in DA, description." }],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "Product",
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"price": { "type": "number" },
"description": { "type": "string" }
},
"required": ["name", "price"]
}
}
},
"plugins": [{ "id": "response-healing" }]
}'| The model wrote | You receive |
|---|---|
{"name": "Alice", "age": 30 | {"name": "Alice", "age": 30} |
| the JSON inside a Markdown code block | the JSON alone |
Here's the data you requested: {"name": "Charlie"} | {"name": "Charlie"} |
{"name": "David", "age": 35,} | {"name": "David", "age": 35} |
{name: "Eve", age: 40} | {"name": "Eve", "age": 40} |
Some answers cannot be repaired — in particular one cut short by max_tokens.
A plugin runs once on every request that names it in plugins. The request is billed in DA on the model's tokens, as its usage.cost shows.