Problem
The errorResponse() function only populates type and message in error responses. The OpenAI API spec requires code and optionally param fields in error objects. Their absence breaks SDK error handling that relies on programmatic error codes.
Current
func errorResponse(errType, message string) map[string]any {
return map[string]any{
"error": map[string]any{
"type": errType,
"message": message,
},
}
}
OpenAI Spec
{
"error": {
"message": "Model 'gpt-5' not found",
"type": "invalid_request_error",
"param": "model",
"code": "model_not_found"
}
}
What Breaks
- Python SDK:
except openai.NotFoundError as e: checks e.code — gets None
- Node SDK:
error.code === 'model_not_found' — gets undefined
- Retry logic: SDKs use
code to decide whether to retry (e.g., insufficient_quota vs rate_limit_exceeded)
- Error monitoring: Sentry/Datadog group by
error.code, not error.message — all errors appear as one group
Proposed Fix
Expand errorResponse to accept optional param and code:
type errOpt struct {
param string
code string
}
func errorResponse(errType, message string, opts ...errOpt) map[string]any {
detail := map[string]any{
"type": errType,
"message": message,
}
if len(opts) > 0 {
if opts[0].param != "" {
detail["param"] = opts[0].param
}
if opts[0].code != "" {
detail["code"] = opts[0].code
}
} else {
// Infer code from type when not explicitly provided
detail["code"] = errType
}
return map[string]any{"error": detail}
}
Then update call sites that should include param:
errorResponse("invalid_request_error", "model is required") → add param: "model"
errorResponse("model_not_found", ...) → add code: "model_not_found"
errorResponse("insufficient_funds", ...) → add code: "insufficient_funds"
Severity
🟠 HIGH — SDK error handling is fundamentally broken without code. Clients cannot programmatically distinguish error types.
Related
Problem
The
errorResponse()function only populatestypeandmessagein error responses. The OpenAI API spec requirescodeand optionallyparamfields in error objects. Their absence breaks SDK error handling that relies on programmatic error codes.Current
OpenAI Spec
{ "error": { "message": "Model 'gpt-5' not found", "type": "invalid_request_error", "param": "model", "code": "model_not_found" } }What Breaks
except openai.NotFoundError as e:checkse.code— getsNoneerror.code === 'model_not_found'— getsundefinedcodeto decide whether to retry (e.g.,insufficient_quotavsrate_limit_exceeded)error.code, noterror.message— all errors appear as one groupProposed Fix
Expand
errorResponseto accept optionalparamandcode:Then update call sites that should include
param:errorResponse("invalid_request_error", "model is required")→ addparam: "model"errorResponse("model_not_found", ...)→ addcode: "model_not_found"errorResponse("insufficient_funds", ...)→ addcode: "insufficient_funds"Severity
🟠 HIGH — SDK error handling is fundamentally broken without
code. Clients cannot programmatically distinguish error types.Related
consumer.go:2549-2557