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.
Structured outputs
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.
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);
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.
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");
}
Avoid deeply nested schemas in the first test. Add fields only after the simple object is stable for your chosen model.
Include prompts that should return empty or rejected results so the application handles edge cases instead of crashing.
Put JSON schema, TypeScript type or Python model changes through the same review so application validation stays aligned.
Verify your selected model through https://www.tken.shop/v1, then add application-side validation before scaling.