microsoft/aspire · error · HttpRequestException

Microsoft Foundry model catalog request failed with HTTP

Error message

Microsoft Foundry model catalog request failed with HTTP {(int)response.StatusCode} ({response.StatusCode}). Response: {GetResponseSnippet(content)}

What it means

GetModelsAsync throws HttpRequestException when the Foundry catalog endpoint returns a non-transient (or retry-exhausted) HTTP error status, embedding the status code and a truncated response body. It lets callers see both the HTTP failure and the server's error payload.

Solutions

  1. Check the HTTP status in the message: fix authentication (az login / correct token) for 401/403.
  2. Verify the catalog endpoint URL and API version for 404/400 responses.
  3. For 429/5xx, wait and re-run — the built-in retry already applied several attempts.
  4. Inspect the response snippet for a server-side error message identifying the root cause.
  5. Ensure network/proxy settings allow the request to reach the Foundry endpoint.
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    await RunGenModelAsync();
}
catch (HttpRequestException ex)
{
    Console.WriteLine($"Catalog fetch failed: {ex.StatusCode}. Check credentials/endpoint and retry.");
}

Prevention

When it happens

Trigger: Any call to ModelClient.GetModelsAsync (via GetAllModelsAsync) where the HTTP response status code is an error status that is not retriable, or where retries of transient statuses were exhausted (attempt >= MaxRequestAttempts).

Common situations: Expired or missing Azure credentials (401/403); wrong catalog endpoint URL (404); service outage (5xx after retries); throttling that outlasted the retry budget (429); corporate proxy blocking the request.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/46af77d679f9e456. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Foundry/tools/GenModel.cs:952

                        await Task.Delay(partialDelay).ConfigureAwait(false);
                        continue;
                    }

                    throw new InvalidOperationException($"The Microsoft Foundry model catalog response included partial failure data in {string.Join(", ", partialFailureFields)}. Refusing to overwrite the generated model descriptors with a partial catalog. Response: {GetResponseSnippet(content)}");
                }

                return content;
            }

            if (IsTransientStatusCode(response.StatusCode) && attempt < MaxRequestAttempts)
            {
                var delay = GetRetryDelay(response, content, attempt);
                Console.WriteLine($"Microsoft Foundry model catalog request failed with HTTP {(int)response.StatusCode} ({response.StatusCode}). Retrying in {delay.TotalSeconds:N0}s (attempt {attempt + 1}/{MaxRequestAttempts}).");
                await Task.Delay(delay).ConfigureAwait(false);
                continue;
            }

            throw new HttpRequestException($"Microsoft Foundry model catalog request failed with HTTP {(int)response.StatusCode} ({response.StatusCode}). Response: {GetResponseSnippet(content)}", inner: null, response.StatusCode);
        }

        throw new InvalidOperationException("The Microsoft Foundry model catalog request loop completed without returning or throwing.");
    }

    public void Dispose()
    {
        _httpClient?.Dispose();
        _handler?.Dispose();
    }

    private void RunFixups(List<ModelEntity> allModels)
    {
        if (_isFoundryLocal)
        {
            // Exclude models that are not listed by foundry local (TBD)
            // c.f. https://github.com/microsoft/Foundry-Local/issues/245#issuecomment-3404022929
            allModels.RemoveAll(m => m.Annotations?.Tags?.TryGetValue("alias", out var alias) is true && alias is not null &&

View on GitHub (pinned to 25830f84bd)