Skip to content

Conversation

@git-hulk
Copy link
Contributor

@git-hulk git-hulk commented Dec 12, 2025

Summary

For Gemini/VertexAI, it concats the model name in the url, so it will return NOT FOUND error if the model name wrongly brings the provider prefix like google/gemini-2.5-flash. And it will raise an error while decoding the empty string with cjson instead of cjson.safe.

Checklist

  • The Pull Request has tests
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/developer.konghq.com - PUT DOCS PR HERE

For Gemini/VertexAI, it concats the model name in the url, so it
will return NOT FOUND error if the model name wrongly brings the
provider prefix like `google/gemini-2.5-flash`. And it will raise an
error while decoding the empty string with `cjson` instead of
`cjson.safe`.
Copilot AI review requested due to automatic review settings December 12, 2025 08:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a panic issue in the ai-proxy plugin when model names contain forward slashes (e.g., "google/gemini-2.5-flash"). When such model names are used with Gemini/VertexAI providers, they are concatenated into the URL path, resulting in invalid API requests that return empty or malformed responses. The fix migrates from the regular cjson library to cjson.safe, which returns errors instead of throwing exceptions, preventing service panics when decoding these empty responses.

Key Changes:

  • Switched from cjson to cjson.safe to handle JSON decode failures gracefully
  • Added explicit error handling with logging for decode failures
  • Used nil-safe access pattern for the decoded response table

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@git-hulk
Copy link
Contributor Author

@oowl @StarlightIbuki Would you mind taking a look this?

@pull-request-size pull-request-size bot added size/M and removed size/S labels Dec 15, 2025
@git-hulk git-hulk force-pushed the fix/panic-when-model-is-invalid branch from fc07f17 to 39b9502 Compare December 15, 2025 03:41
@pull-request-size pull-request-size bot added size/S and removed size/M labels Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants