micro/go-micro · error
no response from API
Error message
no response from API
What it means
Thrown after a successful JSON parse when the Mistral chat completion response contains zero choices. The library guarantees at least one choice to return a Reply, so an empty choices array is treated as 'no response from API'.
Source
Thrown at ai/mistral/mistral.go:203
Choices []struct {
Message struct {
Content string `json:"content"`
ToolCalls []struct {
ID string `json:"id"`
Function struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
} `json:"function"`
} `json:"tool_calls"`
} `json:"message"`
} `json:"choices"`
}
if err := json.Unmarshal(respBody, &chatResp); err != nil {
return nil, nil, fmt.Errorf("failed to parse response: %w", err)
}
if len(chatResp.Choices) == 0 {
return nil, nil, fmt.Errorf("no response from API")
}
choice := chatResp.Choices[0]
response := &ai.Response{Reply: choice.Message.Content}
for _, tc := range choice.Message.ToolCalls {
var input map[string]any
if err := json.Unmarshal([]byte(tc.Function.Arguments), &input); err != nil {
input = map[string]any{}
}
response.ToolCalls = append(response.ToolCalls, ai.ToolCall{
ID: tc.ID,
Name: tc.Function.Name,
Input: input,
})
}
rawMessage := map[string]any{View on GitHub (pinned to 24529f1404)
Solutions
- Log the full response body when choices is empty to inspect any error/metadata fields
- Verify the model name and prompt are valid for the Mistral API
- Add an error/message field to the response struct and surface it instead of the generic message
- Retry the request once; transient empty responses are often intermittent
Example fix
// before
if len(chatResp.Choices) == 0 {
return nil, nil, fmt.Errorf("no response from API")
}
// after
if len(chatResp.Choices) == 0 {
return nil, nil, fmt.Errorf("no response from API (status %s): %s", httpResp.Status, string(respBody))
} Defensive patterns
Strategy: retry
Validate before calling
if req.Model == "" {
return fmt.Errorf("model name is required")
} Type guard
func hasChoices(c *chatCompletionResponse) bool {
return c != nil && len(c.Choices) > 0
} Try / catch
resp, err := provider.Generate(ctx, req)
if err != nil {
if strings.Contains(err.Error(), "no response from API") {
// retry once with backoff, or surface prompt/model issue to user
}
return err
} Prevention
- Retry transient empty responses with backoff
- Validate model names against the provider's model list
- Log the full response body when choices are empty
- Check content-filter behavior of your prompts
When it happens
Trigger: len(chatResp.Choices) == 0 in callAPI — the API responded 200 with an empty choices array, e.g. the prompt was filtered, the model produced no content, or an error payload still returned HTTP 200 with choices omitted.
Common situations: Content-filtered prompts; a model name that returns an odd empty completion; API returning {"choices":[]} during partial outages; error responses that happen to parse but carry no choices.
Understand the failure class
Background: "empty response", "returned no data", "empty embeddings": what HTTP 200-with-empty-body errors mean across libraries — this error's family across 36 libraries.
Related errors
- no response from API
- no response from API
- ${rsp.Status}: ${body} (dynamic HTTP status and body)
- video completed but no outputs returned
- failed to parse response: %w
AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01).
Data as JSON: /api/errors/1252893d042543ba.
Report an issue: GitHub.