Structured Outputs
Request JSON responses from supported OpenAI-compatible models.
Structured Outputs
These are capability-dependent templates, not the first production request. K2.7 does not currently have verified structured-output support. Replace the placeholder only with a callable model whose discovery capabilities include structured_output.
Use response_format to ask supported models for structured JSON instead of free-form text.
Qufas AI accepts OpenAI-compatible JSON mode and JSON Schema requests and forwards them through the provider layer when the selected model supports structured output.
Supported formats
textfor normal text output.json_objectfor JSON mode.json_schemafor an explicit schema request.
JSON Mode
Set response_format.type to json_object when you need the assistant message content to be a JSON object.
1{2 "model": "<structured-output-capable-model-id>",3 "messages": [4 {5 "role": "user",6 "content": "Return a JSON object with a project name and priority."7 }8 ],9 "response_format": {10 "type": "json_object"11 }12}JSON Schema
Use json_schema when you want to provide an explicit output shape. Qufas validates the request format before forwarding it to the provider.
1{2 "model": "<structured-output-capable-model-id>",3 "messages": [4 {5 "role": "user",6 "content": "Extract the user information from: John is 25 years old."7 }8 ],9 "response_format": {10 "type": "json_schema",11 "json_schema": {12 "name": "user_info",13 "schema": {14 "type": "object",15 "properties": {16 "name": {17 "type": "string"18 },19 "age": {20 "type": "integer"21 }22 },23 "required": ["name", "age"],24 "additionalProperties": false25 },26 "strict": true27 }28 }29}Examples
Existing OpenAI SDK integrations can pass response_format without changing the client setup.
1from openai import OpenAI2 3client = OpenAI(4 api_key="qf_sk_xxxx",5 base_url="https://qufas-ai.vercel.app/v1"6)7 8response = client.chat.completions.create(9 model="<structured-output-capable-model-id>",10 messages=[11 {12 "role": "user",13 "content": "Extract user information from: John is 25 years old."14 }15 ],16 response_format={17 "type": "json_object"18 }19)20 21print(response.choices[0].message.content)Streaming
Structured output requests can also use stream: true. The response is streamed as OpenAI-compatible SSE chunks in choices[0].delta.content.
1{2 "choices": [3 {4 "message": {5 "role": "assistant",6 "content": "{\"name\":\"John\",\"age\":25}"7 }8 }9 ]10}Errors
Invalid response formats return a 400 invalid_request_error before the request reaches the upstream provider.
Was this page helpful?
