Skip to content

fix: handle API error responses in Vertex AI OpenAI-compat endpoint#451

Open
shelvick wants to merge 2 commits intoagentjido:mainfrom
shelvick:fix/vertex-openai-compat-error-handling
Open

fix: handle API error responses in Vertex AI OpenAI-compat endpoint#451
shelvick wants to merge 2 commits intoagentjido:mainfrom
shelvick:fix/vertex-openai-compat-error-handling

Conversation

@shelvick
Copy link
Contributor

Summary

  • Add error-handling clause to OpenAICompat.parse_response/3 that detects error bodies (%{"error" => _}) and converts them to ReqLLM.Error.API.Request structs with proper status, reason, and response_body
  • Update GoogleVertex.decode_response/1 to return API errors through Req's pipeline ({request, error}) instead of raising, consistent with Azure and Bedrock providers
  • Add Step.Error clause for API.Request exceptions that preserves their fields instead of double-wrapping with status: nil
  • Handle multiple error body formats: Google Cloud (code + message), OpenAI-style (message + type), plain string, and unknown structures

Test plan

  • 4 new unit tests for parse_response/3 error handling (Google Cloud format, OpenAI format, string error, unknown structure)
  • All 25 OpenAI-compat tests pass
  • Full test suite passes (2281 tests, 0 failures)

…onse

When Vertex AI MaaS endpoints return HTTP error responses (e.g. 429,
500), the JSON body contains an "error" key instead of "choices". Without
this fix, parse_response passes the error body to the success path,
producing a garbage response and losing the error message/status.

Add an error-handling clause to OpenAICompat.parse_response/3 that
detects error bodies and converts them to ReqLLM.Error.API.Request
structs with proper status, reason, and response_body. Update
GoogleVertex.decode_response to return the error through Req's pipeline
instead of raising. Add a Step.Error clause to preserve API.Request
fields when re-processing, preventing double-wrapping that would discard
status and response_body.
Vertex AI may wrap the response body in a single-element list. Add a
clause to unwrap [body] and delegate to the existing parse_response
clauses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant