sipeed/picoclaw · error

error fetching models: %w

Error message

error fetching models: %w

What it means

Wrapped error from providers.FetchAntigravityModels, which POSTs to the Antigravity Cloud Code Assist endpoint /v1internal:fetchAvailableModels with the stored OAuth Bearer token and a 15s HTTP timeout (pkg/providers/oauth/antigravity_provider.go:554). The underlying error can be a transport failure, a non-200 response such as 'fetchAvailableModels failed (HTTP 401)' for an expired token or HTTP 429 for quota, or a JSON parse error on the response body. The %w preserves the cause for errors.Is/As inspection.

Source

Thrown at cmd/picoclaw/internal/auth/helpers.go:463

	if cred.NeedsRefresh() && cred.RefreshToken != "" {
		oauthCfg := auth.GoogleAntigravityOAuthConfig()
		refreshed, refreshErr := auth.RefreshAccessToken(cred, oauthCfg)
		if refreshErr == nil {
			cred = refreshed
			_ = auth.SetCredential("google-antigravity", cred)
		}
	}

	projectID := cred.ProjectID
	if projectID == "" {
		return fmt.Errorf("no project id stored. Try logging in again")
	}

	fmt.Printf("Fetching models for project: %s\n\n", projectID)

	models, err := providers.FetchAntigravityModels(cred.AccessToken, projectID)
	if err != nil {
		return fmt.Errorf("error fetching models: %w", err)
	}

	if len(models) == 0 {
		return fmt.Errorf("no models available")
	}

	fmt.Println("Available Antigravity Models:")
	fmt.Println("-----------------------------")
	for _, m := range models {
		status := "✓"
		if m.IsExhausted {
			status = "✗ (quota exhausted)"
		}
		name := m.ID
		if m.DisplayName != "" {
			name = fmt.Sprintf("%s (%s)", m.ID, m.DisplayName)
		}
		fmt.Printf("  %s %s\n", status, name)

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Re-login with the Antigravity auth command to refresh the access token, then retry
  2. Read the wrapped cause: HTTP 401/403 means token, HTTP 429 means wait for the reported quotaResetDelay, JSON/parse text means API contract change
  3. Check network/proxy connectivity to the Antigravity API host
  4. If HTTP 429, wait for the quota reset time shown in the message before retrying
  5. Update picoclaw to the latest version in case the fetchAvailableModels endpoint or required headers changed

Example fix

// before
models, err := providers.FetchAntigravityModels(cred.AccessToken, projectID)
if err != nil {
	return fmt.Errorf("error fetching models: %w", err)
}

// after: surface an actionable hint for the common auth cause
models, err := providers.FetchAntigravityModels(cred.AccessToken, projectID)
if err != nil {
	if strings.Contains(err.Error(), "HTTP 401") || strings.Contains(err.Error(), "HTTP 403") {
		return fmt.Errorf("error fetching models (token may be expired, try logging in again): %w", err)
	}
	return fmt.Errorf("error fetching models: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify credentials exist and look fresh before calling
if cred.AccessToken == "" {
	return errors.New("not logged in: run the antigravity login command first")
}

Type guard

func isAuthFailure(err error) bool {
	if err == nil {
		return false
	}
	msg := err.Error()
	return strings.Contains(msg, "HTTP 401") || strings.Contains(msg, "HTTP 403")
}

Try / catch

models, err := providers.FetchAntigravityModels(cred.AccessToken, projectID)
if err != nil {
	if isAuthFailure(err) {
		// re-login flow, then retry once
	} else if strings.Contains(err.Error(), "HTTP 429") {
		// backoff until the reported quotaResetDelay elapses
	} else {
		return fmt.Errorf("error fetching models: %w", err)
	}
}

Prevention

When it happens

Trigger: Running the models-listing auth helper with a stale/revoked Antigravity access token (HTTP 401/403); hitting the API quota (HTTP 429 'rate limit exceeded'); network offline or DNS failure; API endpoint/UA header change making the server return HTML instead of JSON; slow network exceeding the hardcoded 15s http.Client timeout.

Common situations: User logged in days ago and the token expired, then runs the models command; corporate proxy blocks googleapis domains; quota window exhausted after heavy use; picoclaw version lagging an upstream Antigravity API contract change.

Related errors


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/12833cb4d2a37944. Report an issue: GitHub.