[{"data":1,"prerenderedAt":684},["ShallowReactive",2],{"docs-nav-titles":3,"page-docs_en-\u002Fguides\u002Fjson-output":52},{"en":4,"id":39},{"\u002Fauthentication":5,"\u002Fchangelog":6,"\u002Fguides\u002Fbilling":7,"\u002Fguides\u002Ferrors":8,"\u002Fguides\u002Fjson-output":9,"\u002Fguides\u002Frate-limits":10,"\u002Fguides\u002Freasoning":11,"\u002Fguides\u002Fstreaming":12,"\u002Fguides\u002Ftool-calling":13,"\u002Fguides\u002Ftop-up":14,"\u002F":15,"\u002Fintegrations\u002Faider":16,"\u002Fintegrations\u002Fclaude-code":17,"\u002Fintegrations\u002Fcline":18,"\u002Fintegrations\u002Fcontinue":19,"\u002Fintegrations\u002Fgoose":20,"\u002Fintegrations\u002Fhermes":21,"\u002Fintegrations":22,"\u002Fintegrations\u002Fkilo-code":23,"\u002Fintegrations\u002Flangchain":24,"\u002Fintegrations\u002Foh-my-pi":25,"\u002Fintegrations\u002Fopenai-sdk":26,"\u002Fintegrations\u002Fopenclaw":27,"\u002Fintegrations\u002Fopencode":28,"\u002Fintegrations\u002Fpi":29,"\u002Fintegrations\u002Fvercel-ai-sdk":30,"\u002Fintegrations\u002Fzed":31,"\u002Fmodels":32,"\u002Fquickstart":33,"\u002Freference\u002Fchat-completions":34,"\u002Freference":22,"\u002Freference\u002Fmessages":35,"\u002Freference\u002Fmodels":36,"\u002Freference\u002Fmodels-retrieve":37,"\u002Fsupport":38},"Authentication","Changelog","Billing","Errors & retries","JSON output","Rate limits","Reasoning content","Streaming","Tool calling","Topping up with QRIS","Introduction","Aider","Claude Code","Cline","Continue","Goose","Hermes Agent","Overview","Kilo Code","LangChain (Python)","Oh My Pi","OpenAI SDKs","OpenClaw","OpenCode","Pi","Vercel AI SDK","Zed","Models","Quickstart","Chat completions","Messages","List models","Retrieve a model","Support",{"\u002Fauthentication":40,"\u002Fchangelog":6,"\u002Fguides\u002Fbilling":7,"\u002Fguides\u002Ferrors":41,"\u002Fguides\u002Fjson-output":42,"\u002Fguides\u002Frate-limits":43,"\u002Fguides\u002Freasoning":44,"\u002Fguides\u002Fstreaming":12,"\u002Fguides\u002Ftool-calling":13,"\u002Fguides\u002Ftop-up":45,"\u002F":46,"\u002Fintegrations\u002Faider":16,"\u002Fintegrations\u002Fclaude-code":17,"\u002Fintegrations\u002Fcline":18,"\u002Fintegrations\u002Fcontinue":19,"\u002Fintegrations\u002Fgoose":20,"\u002Fintegrations\u002Fhermes":21,"\u002Fintegrations":47,"\u002Fintegrations\u002Fkilo-code":23,"\u002Fintegrations\u002Flangchain":24,"\u002Fintegrations\u002Foh-my-pi":25,"\u002Fintegrations\u002Fopenai-sdk":48,"\u002Fintegrations\u002Fopenclaw":27,"\u002Fintegrations\u002Fopencode":28,"\u002Fintegrations\u002Fpi":29,"\u002Fintegrations\u002Fvercel-ai-sdk":30,"\u002Fintegrations\u002Fzed":31,"\u002Fmodels":49,"\u002Fquickstart":33,"\u002Freference\u002Fchat-completions":34,"\u002Freference":47,"\u002Freference\u002Fmessages":35,"\u002Freference\u002Fmodels":50,"\u002Freference\u002Fmodels-retrieve":51,"\u002Fsupport":38},"Autentikasi","Error & retry","Output JSON","Rate limit","Konten reasoning","Isi saldo dengan QRIS","Pengantar","Ringkasan","OpenAI SDK","Model","Daftar model","Ambil satu model",{"id":53,"title":9,"body":54,"description":676,"extension":677,"eyebrow":678,"meta":679,"navTitle":678,"navigation":132,"path":680,"seo":681,"stem":682,"__hash__":683},"docs_en\u002Fguides\u002Fjson-output.md",{"type":55,"value":56,"toc":672},"minimark",[57,74,79,600,604,658,668],[58,59,60,61,65,66,69,70,73],"p",{},"Set ",[62,63,64],"code",{},"response_format"," to ",[62,67,68],{},"{\"type\": \"json_object\"}"," and the model returns its answer as a single valid JSON object in ",[62,71,72],{},"message.content",".",[75,76,78],"h2",{"id":77},"example","Example",[80,81,82,374],"code-group",{},[83,84,90],"pre",{"className":85,"code":86,"filename":87,"language":88,"meta":89,"style":89},"language-python shiki shiki-themes github-dark-default github-light-default","import json\nimport os\nfrom openai import OpenAI\n\nclient = OpenAI(\n    base_url=\"https:\u002F\u002Fapi.larasrouter.com\u002Fv1\",\n    api_key=os.environ[\"LARAS_API_KEY\"],\n)\n\nresponse = client.chat.completions.create(\n    model=\"deepseek-flash\",\n    response_format={\"type\": \"json_object\"},\n    messages=[\n        {\n            \"role\": \"system\",\n            \"content\": (\n                \"Extract the product and quantity from the message. \"\n                'Reply in JSON like {\"product\": \"string\", \"quantity\": 0}.'\n            ),\n        },\n        {\"role\": \"user\", \"content\": \"Saya mau pesan tiga kopi susu gula aren.\"},\n    ],\n)\n\ndata = json.loads(response.choices[0].message.content)\nprint(data)  # {'product': 'kopi susu gula aren', 'quantity': 3}\n","Python","python","",[62,91,92,105,113,127,134,146,162,179,185,190,201,214,237,248,254,267,276,282,288,294,300,327,333,338,343,361],{"__ignoreMap":89},[93,94,97,101],"span",{"class":95,"line":96},"line",1,[93,98,100],{"class":99},"s1PA9","import",[93,102,104],{"class":103},"sUq8j"," json\n",[93,106,108,110],{"class":95,"line":107},2,[93,109,100],{"class":99},[93,111,112],{"class":103}," os\n",[93,114,116,119,122,124],{"class":95,"line":115},3,[93,117,118],{"class":99},"from",[93,120,121],{"class":103}," openai ",[93,123,100],{"class":99},[93,125,126],{"class":103}," OpenAI\n",[93,128,130],{"class":95,"line":129},4,[93,131,133],{"emptyLinePlaceholder":132},true,"\n",[93,135,137,140,143],{"class":95,"line":136},5,[93,138,139],{"class":103},"client ",[93,141,142],{"class":99},"=",[93,144,145],{"class":103}," OpenAI(\n",[93,147,149,153,155,159],{"class":95,"line":148},6,[93,150,152],{"class":151},"sjwWW","    base_url",[93,154,142],{"class":99},[93,156,158],{"class":157},"sHdZ9","\"https:\u002F\u002Fapi.larasrouter.com\u002Fv1\"",[93,160,161],{"class":103},",\n",[93,163,165,168,170,173,176],{"class":95,"line":164},7,[93,166,167],{"class":151},"    api_key",[93,169,142],{"class":99},[93,171,172],{"class":103},"os.environ[",[93,174,175],{"class":157},"\"LARAS_API_KEY\"",[93,177,178],{"class":103},"],\n",[93,180,182],{"class":95,"line":181},8,[93,183,184],{"class":103},")\n",[93,186,188],{"class":95,"line":187},9,[93,189,133],{"emptyLinePlaceholder":132},[93,191,193,196,198],{"class":95,"line":192},10,[93,194,195],{"class":103},"response ",[93,197,142],{"class":99},[93,199,200],{"class":103}," client.chat.completions.create(\n",[93,202,204,207,209,212],{"class":95,"line":203},11,[93,205,206],{"class":151},"    model",[93,208,142],{"class":99},[93,210,211],{"class":157},"\"deepseek-flash\"",[93,213,161],{"class":103},[93,215,217,220,222,225,228,231,234],{"class":95,"line":216},12,[93,218,219],{"class":151},"    response_format",[93,221,142],{"class":99},[93,223,224],{"class":103},"{",[93,226,227],{"class":157},"\"type\"",[93,229,230],{"class":103},": ",[93,232,233],{"class":157},"\"json_object\"",[93,235,236],{"class":103},"},\n",[93,238,240,243,245],{"class":95,"line":239},13,[93,241,242],{"class":151},"    messages",[93,244,142],{"class":99},[93,246,247],{"class":103},"[\n",[93,249,251],{"class":95,"line":250},14,[93,252,253],{"class":103},"        {\n",[93,255,257,260,262,265],{"class":95,"line":256},15,[93,258,259],{"class":157},"            \"role\"",[93,261,230],{"class":103},[93,263,264],{"class":157},"\"system\"",[93,266,161],{"class":103},[93,268,270,273],{"class":95,"line":269},16,[93,271,272],{"class":157},"            \"content\"",[93,274,275],{"class":103},": (\n",[93,277,279],{"class":95,"line":278},17,[93,280,281],{"class":157},"                \"Extract the product and quantity from the message. \"\n",[93,283,285],{"class":95,"line":284},18,[93,286,287],{"class":157},"                'Reply in JSON like {\"product\": \"string\", \"quantity\": 0}.'\n",[93,289,291],{"class":95,"line":290},19,[93,292,293],{"class":103},"            ),\n",[93,295,297],{"class":95,"line":296},20,[93,298,299],{"class":103},"        },\n",[93,301,303,306,309,311,314,317,320,322,325],{"class":95,"line":302},21,[93,304,305],{"class":103},"        {",[93,307,308],{"class":157},"\"role\"",[93,310,230],{"class":103},[93,312,313],{"class":157},"\"user\"",[93,315,316],{"class":103},", ",[93,318,319],{"class":157},"\"content\"",[93,321,230],{"class":103},[93,323,324],{"class":157},"\"Saya mau pesan tiga kopi susu gula aren.\"",[93,326,236],{"class":103},[93,328,330],{"class":95,"line":329},22,[93,331,332],{"class":103},"    ],\n",[93,334,336],{"class":95,"line":335},23,[93,337,184],{"class":103},[93,339,341],{"class":95,"line":340},24,[93,342,133],{"emptyLinePlaceholder":132},[93,344,346,349,351,354,358],{"class":95,"line":345},25,[93,347,348],{"class":103},"data ",[93,350,142],{"class":99},[93,352,353],{"class":103}," json.loads(response.choices[",[93,355,357],{"class":356},"sYnYM","0",[93,359,360],{"class":103},"].message.content)\n",[93,362,364,367,370],{"class":95,"line":363},26,[93,365,366],{"class":356},"print",[93,368,369],{"class":103},"(data)  ",[93,371,373],{"class":372},"shPRk","# {'product': 'kopi susu gula aren', 'quantity': 3}\n",[83,375,380],{"className":376,"code":377,"filename":378,"language":379,"meta":89,"style":89},"language-typescript shiki shiki-themes github-dark-default github-light-default","import OpenAI from \"openai\";\n\nconst client = new OpenAI({\n  baseURL: \"https:\u002F\u002Fapi.larasrouter.com\u002Fv1\",\n  apiKey: process.env.LARAS_API_KEY,\n});\n\nconst response = await client.chat.completions.create({\n  model: \"deepseek-flash\",\n  response_format: { type: \"json_object\" },\n  messages: [\n    {\n      role: \"system\",\n      content:\n        'Extract the product and quantity from the message. Reply in JSON like {\"product\": \"string\", \"quantity\": 0}.',\n    },\n    { role: \"user\", content: \"Saya mau pesan tiga kopi susu gula aren.\" },\n  ],\n});\n\nconst data = JSON.parse(response.choices[0].message.content ?? \"{}\");\nconsole.log(data); \u002F\u002F { product: 'kopi susu gula aren', quantity: 3 }\n","Node.js","typescript",[62,381,382,397,401,422,431,441,446,450,470,479,489,494,499,508,513,520,525,539,544,548,552,586],{"__ignoreMap":89},[93,383,384,386,389,391,394],{"class":95,"line":96},[93,385,100],{"class":99},[93,387,388],{"class":103}," OpenAI ",[93,390,118],{"class":99},[93,392,393],{"class":157}," \"openai\"",[93,395,396],{"class":103},";\n",[93,398,399],{"class":95,"line":107},[93,400,133],{"emptyLinePlaceholder":132},[93,402,403,406,409,412,415,419],{"class":95,"line":115},[93,404,405],{"class":99},"const",[93,407,408],{"class":356}," client",[93,410,411],{"class":99}," =",[93,413,414],{"class":99}," new",[93,416,418],{"class":417},"sK34n"," OpenAI",[93,420,421],{"class":103},"({\n",[93,423,424,427,429],{"class":95,"line":129},[93,425,426],{"class":103},"  baseURL: ",[93,428,158],{"class":157},[93,430,161],{"class":103},[93,432,433,436,439],{"class":95,"line":136},[93,434,435],{"class":103},"  apiKey: process.env.",[93,437,438],{"class":356},"LARAS_API_KEY",[93,440,161],{"class":103},[93,442,443],{"class":95,"line":148},[93,444,445],{"class":103},"});\n",[93,447,448],{"class":95,"line":164},[93,449,133],{"emptyLinePlaceholder":132},[93,451,452,454,457,459,462,465,468],{"class":95,"line":181},[93,453,405],{"class":99},[93,455,456],{"class":356}," response",[93,458,411],{"class":99},[93,460,461],{"class":99}," await",[93,463,464],{"class":103}," client.chat.completions.",[93,466,467],{"class":417},"create",[93,469,421],{"class":103},[93,471,472,475,477],{"class":95,"line":187},[93,473,474],{"class":103},"  model: ",[93,476,211],{"class":157},[93,478,161],{"class":103},[93,480,481,484,486],{"class":95,"line":192},[93,482,483],{"class":103},"  response_format: { type: ",[93,485,233],{"class":157},[93,487,488],{"class":103}," },\n",[93,490,491],{"class":95,"line":203},[93,492,493],{"class":103},"  messages: [\n",[93,495,496],{"class":95,"line":216},[93,497,498],{"class":103},"    {\n",[93,500,501,504,506],{"class":95,"line":239},[93,502,503],{"class":103},"      role: ",[93,505,264],{"class":157},[93,507,161],{"class":103},[93,509,510],{"class":95,"line":250},[93,511,512],{"class":103},"      content:\n",[93,514,515,518],{"class":95,"line":256},[93,516,517],{"class":157},"        'Extract the product and quantity from the message. Reply in JSON like {\"product\": \"string\", \"quantity\": 0}.'",[93,519,161],{"class":103},[93,521,522],{"class":95,"line":269},[93,523,524],{"class":103},"    },\n",[93,526,527,530,532,535,537],{"class":95,"line":278},[93,528,529],{"class":103},"    { role: ",[93,531,313],{"class":157},[93,533,534],{"class":103},", content: ",[93,536,324],{"class":157},[93,538,488],{"class":103},[93,540,541],{"class":95,"line":284},[93,542,543],{"class":103},"  ],\n",[93,545,546],{"class":95,"line":290},[93,547,445],{"class":103},[93,549,550],{"class":95,"line":296},[93,551,133],{"emptyLinePlaceholder":132},[93,553,554,556,559,561,564,566,569,572,574,577,580,583],{"class":95,"line":302},[93,555,405],{"class":99},[93,557,558],{"class":356}," data",[93,560,411],{"class":99},[93,562,563],{"class":356}," JSON",[93,565,73],{"class":103},[93,567,568],{"class":417},"parse",[93,570,571],{"class":103},"(response.choices[",[93,573,357],{"class":356},[93,575,576],{"class":103},"].message.content ",[93,578,579],{"class":99},"??",[93,581,582],{"class":157}," \"{}\"",[93,584,585],{"class":103},");\n",[93,587,588,591,594,597],{"class":95,"line":329},[93,589,590],{"class":103},"console.",[93,592,593],{"class":417},"log",[93,595,596],{"class":103},"(data); ",[93,598,599],{"class":372},"\u002F\u002F { product: 'kopi susu gula aren', quantity: 3 }\n",[75,601,603],{"id":602},"get-reliable-json","Get reliable JSON",[605,606,607,615,632,646],"ul",{},[608,609,610,614],"li",{},[611,612,613],"strong",{},"Say \"JSON\" in the prompt and show the shape."," JSON mode guarantees valid syntax, not your schema. Describe the keys and types you expect, ideally with an example object, in the system or user message.",[608,616,617,623,624,627,628,631],{},[611,618,619,620,73],{},"Leave room in ",[62,621,622],{},"max_tokens"," If the output hits the cap, the JSON is cut off and will not parse. Check that ",[62,625,626],{},"finish_reason"," is ",[62,629,630],{},"\"stop\""," before parsing.",[608,633,634,637,638,641,642,645],{},[611,635,636],{},"Validate the result."," Parse with ",[62,639,640],{},"json.loads"," \u002F ",[62,643,644],{},"JSON.parse"," and validate against your schema (for example with Pydantic or Zod) before you use it.",[608,647,648,651,652,657],{},[611,649,650],{},"Use tools for strict schemas."," If you need the model to fill a fixed set of arguments, a function in ",[653,654,656],"a",{"href":655},"\u002Fguides\u002Ftool-calling","tool calling"," with a JSON Schema is often a better fit.",[659,660,662],"callout",{"type":661},"info",[58,663,664,667],{},[62,665,666],{},"response_format: {\"type\": \"json_object\"}"," is the supported mode. Other values are forwarded to the model as sent; check the result rather than assuming a stricter guarantee.",[669,670,671],"style",{},"html pre.shiki code .s1PA9, html code.shiki .s1PA9{--shiki-default:#FF7B72;--shiki-light:#CF222E}html pre.shiki code .sUq8j, html code.shiki .sUq8j{--shiki-default:#E6EDF3;--shiki-light:#1F2328}html pre.shiki code .sjwWW, html code.shiki .sjwWW{--shiki-default:#FFA657;--shiki-light:#953800}html pre.shiki code .sHdZ9, html code.shiki .sHdZ9{--shiki-default:#A5D6FF;--shiki-light:#0A3069}html pre.shiki code .sYnYM, html code.shiki .sYnYM{--shiki-default:#79C0FF;--shiki-light:#0550AE}html pre.shiki code .shPRk, html code.shiki .shPRk{--shiki-default:#8B949E;--shiki-light:#6E7781}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html pre.shiki code .sK34n, html code.shiki .sK34n{--shiki-default:#D2A8FF;--shiki-light:#8250DF}",{"title":89,"searchDepth":115,"depth":115,"links":673},[674,675],{"id":77,"depth":107,"text":78},{"id":602,"depth":107,"text":603},"Make deepseek-flash return a valid JSON object with response_format.","md",null,{},"\u002Fguides\u002Fjson-output",{"title":9,"description":676},"guides\u002Fjson-output","7Bo4hPxrNTT9b_4I4qL2ekFzcsbzDfksdeTYmcPDIhE",1793333617466]