micro/go-micro · error

API error: %s

Error message

API error: %s

What it means

After decoding the submit response, GenerateImage checks the application-level code field; anything other than 200 throws this error carrying the API's message string. It means the HTTP call succeeded but AtlasCloud rejected the generation request at the business-logic level, before polling begins.

Source

Thrown at ai/atlascloud/atlascloud.go:979

	respBody, _ := io.ReadAll(httpResp.Body)
	if httpResp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("API error (%s): %s", httpResp.Status, string(respBody))
	}

	var submitResp struct {
		Code int    `json:"code"`
		Msg  string `json:"message"`
		Data struct {
			ID     string `json:"id"`
			Status string `json:"status"`
		} `json:"data"`
	}
	if err := json.Unmarshal(respBody, &submitResp); err != nil {
		return nil, fmt.Errorf("failed to parse submit response: %w", err)
	}
	if submitResp.Code != 200 {
		return nil, fmt.Errorf("API error: %s", submitResp.Msg)
	}

	predictionID := submitResp.Data.ID
	pollURL := strings.TrimRight(p.opts.BaseURL, "/") + "/api/v1/model/prediction/" + predictionID

	ticker := time.NewTicker(2 * time.Second)
	defer ticker.Stop()

	for {
		select {
		case <-ctx.Done():
			return nil, ctx.Err()
		case <-ticker.C:
			result, err := p.pollPrediction(ctx, pollURL)
			if err != nil {
				return nil, err
			}
			if result != nil {

View on GitHub (pinned to 24529f1404)

Solutions

  1. Read the Msg in the error — it states the business-level reason from AtlasCloud.
  2. For auth codes, re-check/rotate the API key used by the provider options.
  3. For quota codes, check billing/limits on the AtlasCloud dashboard and back off.
  4. Validate model name and image parameters (dimensions, prompt length) against current AtlasCloud docs.
Defensive patterns

Strategy: try-catch

Validate before calling

if model == "" || !slices.Contains(supportedAtlasImageModels, model) {
    return fmt.Errorf("unsupported AtlasCloud image model: %q", model)
}

Try / catch

img, err := provider.GenerateImage(ctx, req)
if err != nil {
    if strings.Contains(err.Error(), "API error:") {
        // business-level rejection: read the message, adjust key/quota/params
        return fmt.Errorf("atlascloud rejected generation: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: submitResp.Code != 200 on a 200 HTTP response — e.g. code 401/1001 for invalid key, 429 for quota, or validation codes for unsupported parameters in the image request.

Common situations: Valid HTTP but invalid API key at the application layer, insufficient credits/quota for image generation, model name or parameter values rejected by AtlasCloud's validation, or deprecated model referenced.

Related errors


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