Json
- GPT-4o returns JSON with trailing comma in tool call
GPT-4o returns JSON with trailing comma in tool call While parsing function‑call output from GPT‑4o the JSON loader threw: json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 98 (char 97) The model emitted: { "name": "getStockPrice", "arguments": { "ticker": "AMD", }, "id": "abc" } Note the trailing comma after "AMD". Added a pre‑parse scrub: import re, json clean = re.sub(r",\s*([}\]])", r"\1", raw) data = json.loads(clean) Also set response_format={"type":"json_object"} in the request; 4o obeys the flag half the time.
- OpenRouter API response missing text in JSON payload
OpenRouter API response missing ’text’ in JSON payload Testing OpenRouter with gpt‑4 turbo. Request looked fine but the completion field came back empty: { "id":"chatcmpl-xxxx", "choices":[ {"index":0,"logprobs":null,"finish_reason":"stop"} ], "model":"gpt-4-turbo-preview", "usage":{...} } No choices[0].message.content. cURL request: curl https://openrouter.ai/api/v1/chat/completions -H "Authorization: Bearer $OPENROUTER_KEY" -H "Content-Type: application/json" -d '{"model":"gpt-4-turbo-preview","messages":[{"role":"user","content":"hi"}]}' Turns out OpenRouter now requires the header HTTP-Referer (your site) and X-Title (app name) for non‑localhost keys.