{"record":{"id":"886f1b8d0dd45a83","repo":"micro/go-micro","slug":"no-response-from-api-886f1b","errorCode":null,"errorMessage":"no response from API","messagePattern":"no response from API","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ai/openai/openai.go","lineNumber":353,"sourceCode":"\t\t\tMessage struct {\n\t\t\t\tContent   string `json:\"content\"`\n\t\t\t\tToolCalls []struct {\n\t\t\t\t\tID       string `json:\"id\"`\n\t\t\t\t\tFunction struct {\n\t\t\t\t\t\tName      string `json:\"name\"`\n\t\t\t\t\t\tArguments string `json:\"arguments\"`\n\t\t\t\t\t} `json:\"function\"`\n\t\t\t\t} `json:\"tool_calls\"`\n\t\t\t} `json:\"message\"`\n\t\t} `json:\"choices\"`\n\t}\n\n\tif err := json.Unmarshal(respBody, &chatResp); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to parse response: %w\", err)\n\t}\n\n\tif len(chatResp.Choices) == 0 {\n\t\treturn nil, nil, fmt.Errorf(\"no response from API\")\n\t}\n\n\tchoice := chatResp.Choices[0]\n\tresponse := &ai.Response{\n\t\tReply: choice.Message.Content,\n\t\tUsage: ai.Usage{InputTokens: chatResp.Usage.PromptTokens, OutputTokens: chatResp.Usage.CompletionTokens, TotalTokens: chatResp.Usage.TotalTokens},\n\t}\n\n\t// Extract tool calls\n\tfor _, tc := range choice.Message.ToolCalls {\n\t\tvar input map[string]any\n\t\tif err := json.Unmarshal([]byte(tc.Function.Arguments), &input); err != nil {\n\t\t\tinput = map[string]any{}\n\t\t}\n\t\tresponse.ToolCalls = append(response.ToolCalls, ai.ToolCall{\n\t\t\tID:    tc.ID,\n\t\t\tName:  tc.Function.Name,\n\t\t\tInput: input,","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/ai/openai/openai.go#L335-L371","documentation":"The API returned valid JSON that parsed correctly, but the choices array was empty, so there is no completion to return. The library treats an empty choices list as an unrecoverable empty response rather than returning a nil reply.","triggerScenarios":"callAPI unmarshals chatResp and len(chatResp.Choices) == 0 — typically because the upstream service returned an empty/success-shaped body with no candidates, e.g. content filtered, max_tokens=0-ish configuration, or an unknown/gateway default response.","commonSituations":"Prompt content flagged by moderation on some compatible providers, model name misspelled so a gateway returns an empty stub, gateway/load-balancer returning 200 with empty body on internal errors, requesting with n=0 or degenerate parameters.","solutions":["Log the full respBody to see whether the server explained the empty response","Verify the model name is valid for the endpoint (e.g. gpt-4o, gpt-3.5-turbo)","Re-check request parameters (prompt length, max tokens) and retry with a simple prompt","If using a proxy/gateway to OpenAI, hit the upstream API directly to isolate the empty-response source"],"exampleFix":"// before\nreq := map[string]any{\"model\": \"gpt-4o-mini-x\", \"messages\": msgs} // typo'd model\n// after\nreq := map[string]any{\"model\": \"gpt-4o-mini\", \"messages\": msgs}","handlingStrategy":"fallback","validationCode":"// pre-flight: confirm the model exists\nreq, _ := http.NewRequest(\"GET\", baseURL+\"/v1/models\", nil)\nreq.Header.Set(\"Authorization\", \"Bearer \"+apiKey)\nresp, err := http.DefaultClient.Do(req)\n// check the chosen model id appears in resp body","typeGuard":null,"tryCatchPattern":"resp, err := provider.Generate(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"no response from API\") {\n    log.Printf(\"empty choices; model=%s — retrying with fallback model\", model)\n    return fallbackProvider.Generate(ctx, req)\n}","preventionTips":["Pin validated model IDs in config, avoid hand-typed names","Retry once with a simpler prompt on empty responses","Bypass gateways when debugging empty 200 bodies","Check provider moderation/content-filter policies for your prompts"],"tags":["openai","empty-response","api-compat"],"backgroundTag":"empty-api-response","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}