Skip to content

Handle non-JSON (HTML) responses from OpenAI-compatible models endpoint#1

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/update-goose-handle-html-response
Draft

Handle non-JSON (HTML) responses from OpenAI-compatible models endpoint#1
Copilot wants to merge 2 commits intomainfrom
copilot/update-goose-handle-html-response

Conversation

Copy link

Copilot AI commented Mar 7, 2026

When an OpenAI-compatible server returns HTML instead of JSON for the /models endpoint (e.g. a misconfigured proxy or gateway), goose crashes with an opaque parse error.

Changes

  • handle_response_openai_compat: Read body as text before parsing JSON. When parsing fails and the body starts with <, include a diagnostic hint in the error: "response appears to be HTML — check that the API endpoint URL is correct".

  • OpenAiCompatibleProvider::fetch_supported_models: Catch RequestFailed errors (non-JSON/HTML 200s, missing endpoints) and return Ok(vec![]) with a warn! log instead of propagating. Auth, rate-limit, and server errors still propagate normally.

  • Unit test: wiremock-backed test asserting an HTML 200 OK on GET /models yields Ok(vec![]).

Summary

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

New #[tokio::test] in openai_compatible.rs using wiremock: spins up a mock server returning HTML for GET /models, asserts fetch_supported_models() returns Ok(vec![]). All existing openai_compatible tests continue to pass.

Related Issues

Screenshots/Demos (for UX changes)

Before:

After:

Original prompt

sometimes an openai server responds with HTML for the root endpoint. right now goose dies when that is the case , update goose to be robust to receiving non-json responses from the root endpoint. add a unit test for it too


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Mar 7, 2026
Co-authored-by: BenGardiner <243321+BenGardiner@users.noreply.github.com>
Copilot AI changed the title [WIP] Update goose to handle non-JSON responses from root endpoint Handle non-JSON (HTML) responses from OpenAI-compatible models endpoint Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants