{"record":{"id":"7ef6f543fc9dc435","repo":"JuliusBrussee/caveman","slug":"rewriter-decode-openai-response-w","errorCode":null,"errorMessage":"rewriter: decode openai response: %w","messagePattern":"rewriter: decode openai response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rewriter/provider.go","lineNumber":145,"sourceCode":"\t})\n\tif err != nil {\n\t\treturn completion{}, err\n\t}\n\n\tvar decoded struct {\n\t\tChoices []struct {\n\t\t\tMessage struct {\n\t\t\t\tContent string `json:\"content\"`\n\t\t\t} `json:\"message\"`\n\t\t\tFinishReason string `json:\"finish_reason\"`\n\t\t} `json:\"choices\"`\n\t\tUsage struct {\n\t\t\tPrompt     int `json:\"prompt_tokens\"`\n\t\t\tCompletion int `json:\"completion_tokens\"`\n\t\t} `json:\"usage\"`\n\t}\n\tif err := json.Unmarshal(raw, &decoded); err != nil {\n\t\treturn completion{}, fmt.Errorf(\"rewriter: decode openai response: %w\", err)\n\t}\n\tvar text, stop string\n\tif len(decoded.Choices) > 0 {\n\t\ttext = decoded.Choices[0].Message.Content\n\t\tstop = decoded.Choices[0].FinishReason\n\t}\n\treturn completion{\n\t\ttext:         text,\n\t\tstopReason:   stop,\n\t\tinputTokens:  decoded.Usage.Prompt,\n\t\toutputTokens: decoded.Usage.Completion,\n\t}, nil\n}\n\n// openAIAcceptsTemperature reports whether a chat-completions model still takes\n// a caller-set temperature. The reasoning families (gpt-5*, o1/o3/o4*) do not.\nfunc openAIAcceptsTemperature(model string) bool {\n\tname := strings.ToLower(strings.TrimSpace(model))","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/rewriter/provider.go#L127-L163","documentation":"completeOpenAI got a 2xx from the OpenAI-compatible chat-completions endpoint but the body did not decode into the expected choices[]/usage structure. The endpoint is likely not actually OpenAI-compatible (different schema, proxied error JSON, or an HTML page returned with success status).","triggerScenarios":"Thrown at rewriter/provider.go:145 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the raw response body to see the actual schema returned","Verify the endpoint truly implements OpenAI chat-completions response format","Update the decoder to match the provider's actual response shape"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}