Structured outputs

Test JSON schema outputs through TKEN

Use TKEN's OpenAI-compatible base URL for schema-bound extraction tests, then validate every response in application code before relying on it for production automation.

Chat completions JSON schema smoke test
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.TKEN_API_KEY,
  baseURL: "https://www.tken.shop/v1"
});

const response = await client.chat.completions.create({
  model: process.env.TKEN_CHAT_MODEL,
  messages: [{ role: "user", content: "Extract name and priority." }],
  response_format: {
    type: "json_schema",
    json_schema: {
      name: "ticket",
      strict: true,
      schema: {
        type: "object",
        additionalProperties: false,
        required: ["name", "priority"],
        properties: {
          name: { type: "string" },
          priority: { type: "string", enum: ["low", "medium", "high"] }
        }
      }
    }
  }
});

console.log(response.choices[0].message.content);
Use strict schemas where supported
Validate responses in your app
Keep a repair path for failures

Compatibility-first rollout

Structured outputs can depend on SDK version, endpoint behavior and routed model capability. Run the exact model and schema you intend to ship before making it part of a critical workflow.

Validation minimum guardrail
const parsed = JSON.parse(response.choices[0].message.content);

if (!["low", "medium", "high"].includes(parsed.priority)) {
  throw new Error("Unexpected priority");
}

if (typeof parsed.name !== "string" || !parsed.name.trim()) {
  throw new Error("Missing name");
}

Structured output checklist

1. Start with a small schema

Avoid deeply nested schemas in the first test. Add fields only after the simple object is stable for your chosen model.

2. Test refusals and invalid inputs

Include prompts that should return empty or rejected results so the application handles edge cases instead of crashing.

3. Keep schema and types together

Put JSON schema, TypeScript type or Python model changes through the same review so application validation stays aligned.

Disclosure: TKEN is an independent third-party API gateway. Confirm structured-output support against your selected model before production use.

Run one schema smoke test

Verify your selected model through https://www.tken.shop/v1, then add application-side validation before scaling.