Skip to content
Docs

Šis puslapis dar neišverstas, todėl rodomas angliškai.

Structured outputs

Ask for JSON with response_format on /chat/completions. When it is set, the router only

Ask for JSON with response_format on /chat/completions. When it is set, the router only picks models that support JSON output, and ORYVOX validates the answer before returning it; an invalid answer counts as a failed attempt and triggers a fallback.

JSON mode

{
  "model": "oryvox-fast",
  "messages": [{"role": "user", "content": "List three primary colours as JSON: {\"colours\": [...]}"}],
  "response_format": {"type": "json_object"}
}

JSON schema

const completion = await client.chat.completions.create({
  model: 'oryvox-balanced',
  messages: [{ role: 'user', content: 'Extract the invoice: "ACME, INV-42, 120.50 EUR"' }],
  response_format: {
    type: 'json_schema',
    json_schema: {
      name: 'invoice',
      strict: true,
      schema: {
        type: 'object',
        properties: {
          vendor: { type: 'string' },
          number: { type: 'string' },
          amount: { type: 'number' },
          currency: { type: 'string' },
        },
        required: ['vendor', 'number', 'amount', 'currency'],
        additionalProperties: false,
      },
    },
  },
});
const invoice = JSON.parse(completion.choices[0].message.content!);
completion = client.chat.completions.create(
    model="oryvox-balanced",
    messages=[{"role": "user", "content": 'Extract the invoice: "ACME, INV-42, 120.50 EUR"'}],
    response_format={"type": "json_schema", "json_schema": {"name": "invoice", "strict": True, "schema": schema}},
)
invoice = json.loads(completion.choices[0].message.content)

Tips

  • Keep schemas small and flat; every property costs tokens.
  • Use optimization.preserve for ids that must appear verbatim in the output.
  • Requests with response_format are not eligible for semantic caching (exact caching still applies).
Ar šis puslapis buvo naudingas?