import json
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.naga.ac/v1", api_key=os.environ["NAGAAI_API_KEY"])
response = client.responses.create(
model="deepseek-v4.1-flash",
input="Name one European capital and its country.",
text={
"format": {
"type": "json_schema",
"name": "capital",
"strict": True,
"schema": {
"type": "object",
"properties": {"city": {"type": "string"}, "country": {"type": "string"}},
"required": ["city", "country"],
"additionalProperties": False,
},
}
},
)
print(json.loads(response.output_text))
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.naga.ac/v1", apiKey: process.env.NAGAAI_API_KEY });
const response = await client.responses.create({
model: "deepseek-v4.1-flash",
input: "Name one European capital and its country.",
text: {
format: {
type: "json_schema",
name: "capital",
strict: true,
schema: {
type: "object",
properties: { city: { type: "string" }, country: { type: "string" } },
required: ["city", "country"],
additionalProperties: false,
},
},
},
});
console.log(JSON.parse(response.output_text));
curl https://api.naga.ac/v1/responses \
-H "Authorization: Bearer $NAGAAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash",
"input": "Name one European capital and its country.",
"text": {
"format": {
"type": "json_schema",
"name": "capital",
"strict": true,
"schema": {
"type": "object",
"properties": {"city": {"type": "string"}, "country": {"type": "string"}},
"required": ["city", "country"],
"additionalProperties": false
}
}
}
}'
{"type": "json_object"} in text.format asks for any JSON object. The SDK helper client.responses.parse() builds the same request from a Pydantic or Zod model. On models without schema support NagaAI falls back to JSON mode plus the schema in the prompt, see Structured outputs.