Structured Outputs
FlowAPI supports the familiar response_format pattern for requesting structured responses. The most portable mode is JSON object output.
JSON Mode
To ask the model for valid JSON, set:
{
"response_format": { "type": "json_object" }
}Example request:
{
"model": "deepseek-ai/DeepSeek-V3.2",
"messages": [
{
"role": "system",
"content": "Return valid JSON only."
},
{
"role": "user",
"content": "List 3 supported AI workloads and their best use cases."
}
],
"response_format": { "type": "json_object" }
}Example response:
{
"workloads": [
{
"name": "chat",
"best_for": "interactive assistants and copilots"
},
{
"name": "vision",
"best_for": "image understanding"
},
{
"name": "embedding",
"best_for": "retrieval and semantic search"
}
]
}Prompting Tips
For more reliable structured responses:
- Tell the model to return JSON only.
- Avoid mixing natural-language explanation with the JSON body.
- Keep the requested schema simple unless the model is known to be strong at structured output.
- Validate the result in your application even if the output usually looks correct.
Schema-Based Output
Some upstream models may support stricter schema-constrained output beyond basic json_object, but support is model-dependent and not guaranteed across all providers exposed through FlowAPI.
Use stricter schema enforcement only after testing the exact target model you plan to deploy.
Python Example
from openai import OpenAI
client = OpenAI(
api_key="YOUR_FLOW_API_KEY",
base_url="https://api.flowapi.net/v1"
)
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V3.2",
messages=[
{"role": "system", "content": "Return valid JSON only."},
{"role": "user", "content": "List 3 pricing considerations for model selection."}
],
response_format={"type": "json_object"},
)
print(response.choices[0].message.content)response_format improves output shape but does not remove the need for application-side validation. Always validate and handle malformed JSON safely.
Last updated on