JuliusBrussee/caveman · error
body must be a JSON object
Error message
body must be a JSON object
What it means
The OpenAI request body unmarshalled to a JSON null (root == nil after json.Unmarshal into map[string]json.RawMessage). The transform operates on a top-level object of fields; a null root means the body is not a valid OpenAI chat request.
Solutions
- Send a body whose top-level JSON value is an object, not 'null'
- Log the raw body at the proxy boundary to find which client emitted null
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at engine/pixel/transform_openai.go:690 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18).
Data as JSON: /api/errors/4e1e4a13698335b9.
Report an issue: GitHub.
Appendix: source
Thrown at engine/pixel/transform_openai.go:690
Compress: opts.Compress,
CompressTools: opts.CompressTools,
MinCompressChars: opts.MinCompressChars,
Cols: min(opts.Cols, ResolveGptProfile(model).StripCols),
MultiCol: 1,
CharsPerToken: opts.CharsPerToken,
Reflow: opts.Reflow,
CollapseHistory: opts.CollapseHistory,
History: history,
}
}
func parseOpenAIRoot(body []byte) (map[string]json.RawMessage, error) {
var root map[string]json.RawMessage
if err := json.Unmarshal(body, &root); err != nil {
return nil, err
}
if root == nil {
return nil, errors.New("body must be a JSON object")
}
return root, nil
}
func openAIModel(root map[string]json.RawMessage, opts TransformOptions) string {
if raw, ok := root["model"]; ok {
var model string
if json.Unmarshal(raw, &model) == nil && model != "" {
return model
}
}
return opts.Model
}
func openAIChatContentText(content any) string {
if s, ok := content.(string); ok {
return s
}View on GitHub (pinned to 766dce6b13)