micro/go-micro · error

no response from API

Error message

no response from API

What it means

After a successful JSON decode, callAPI checks that chatResp.Choices is non-empty; if the API returned a valid chat-completion envelope with zero choices, this plain error is thrown. It means the request technically succeeded but the model produced no selectable completion.

Solutions

  1. Inspect the raw response body for a filter/finish_reason indication (log the full body before this check).
  2. Verify the requested model name and that the messages/prompt payload is non-empty and well-formed.
  3. Retry the request; if reproducible, rephrase the prompt to avoid content that may be filtered.
  4. Treat it as retryable transient behavior and add backoff retry at the Generate call site.
Defensive patterns

Strategy: fallback

Try / catch

resp, err := provider.Generate(ctx, req)
if err != nil {
    if strings.Contains(err.Error(), "no response from API") {
        // retry once or fall back to another provider/model
        resp, err = provider.Generate(ctx, req)
    }
    if err != nil {
        return err
    }
}

Prevention

When it happens

Trigger: json.Unmarshal succeeds but len(chatResp.Choices) == 0 — the API replied 200 with choices: [] (or omitted), e.g. the request was entirely filtered or the model returned nothing.

Common situations: Prompt fully consumed by moderation/safety filtering, an invalid model name that the API accepts but yields no output, empty prompt/messages payload, or provider-side degraded responses during outages.

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


AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01). Data as JSON: /api/errors/0af0b5a8e975ec75. Report an issue: GitHub.

Appendix: source

Thrown at ai/atlascloud/atlascloud.go:470

		}
		return nil, nil, &atlascloudAPIError{Status: httpResp.Status, Code: httpResp.StatusCode, Retry: retryAfter, Phase: phase, Summary: atlascloudRequestSummary(req), Body: string(respBody)}
	}

	var chatResp struct {
		Choices []struct {
			Message struct {
				Content   string          `json:"content"`
				ToolCalls []atlasToolCall `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,
		})
	}

View on GitHub (pinned to 24529f1404)