MODEL CAPABILITIES
Structured responses
The API does not enforce a JSON schema. Ask for JSON and validate what comes back.
Not available`response_format` (JSON mode and JSON schema) is not supported: it is accepted and ignored.
OpenAI's response_format parameter is not implemented. A request that includes it is accepted without error, but output is not constrained, so the answer can contain prose, code fences, or a field in the wrong type.
You can still get structured data reliably enough for many tasks: state the exact shape in the prompt, extract the JSON from the reply, validate it in code, and retry if it fails. The example does exactly that.
PROMPT, EXTRACT, VALIDATE
curl https://api.tessen.ai/v1/chat/completions \ -H "Authorization: Bearer $TESSEN_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "z1", "max_tokens": 256, "messages": [{"role": "user", "content": "Return only a JSON object with the keys \"name\" (string) and \"age\" (integer) for this person: Ada Lovelace, 36 years old."}] }'import jsonimport osimport reimport requests PROMPT = 'Return only a JSON object with the keys "name" (string) and "age" (integer) for this person: Ada Lovelace, 36 years old.' def extract(text): match = re.search(r"\{.*\}", text, re.S) data = json.loads(match.group(0)) if match else None if not isinstance(data, dict) or not isinstance(data.get("name"), str) or not isinstance(data.get("age"), int): raise ValueError(f"Not the expected JSON: {text!r}") return data for attempt in range(3): # the API does not enforce a schema, so validate and retry response = requests.post( "https://api.tessen.ai/v1/chat/completions", headers={"Authorization": f"Bearer {os.environ['TESSEN_API_KEY']}"}, json={"model": "z1", "max_tokens": 256, "messages": [{"role": "user", "content": PROMPT}]}, timeout=120, ) response.raise_for_status() try: print(extract(response.json()["choices"][0]["message"]["content"])) break except ValueError as error: print("retrying:", error)const prompt = 'Return only a JSON object with the keys "name" (string) and "age" (integer) for this person: Ada Lovelace, 36 years old.'; function extract(text) { const match = text.match(/\{[\s\S]*\}/); const data = match ? JSON.parse(match[0]) : null; if (!data || typeof data.name !== "string" || !Number.isInteger(data.age)) { throw new Error(`Not the expected JSON: ${text}`); } return data;} for (let attempt = 0; attempt < 3; attempt++) { // the API does not enforce a schema, so validate and retry const response = await fetch("https://api.tessen.ai/v1/chat/completions", { method: "POST", headers: { Authorization: `Bearer ${process.env.TESSEN_API_KEY}`, "Content-Type": "application/json" }, body: JSON.stringify({ model: "z1", max_tokens: 256, messages: [{ role: "user", content: prompt }] }), }); if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`); try { console.log(extract((await response.json()).choices[0].message.content)); break; } catch (error) { console.log("retrying:", error.message); }}Practices that help
- Name every key and its type in the prompt, and say "Return only a JSON object".
- Keep
max_tokenslarge enough for the whole object, or the JSON is cut off withfinish_reason: "length". - Validate with a schema library in your own code, and retry a small fixed number of times.
- For actions, prefer tool calling: function arguments are JSON the model is asked to produce for a declared schema (still validate them).