fix: forward cachedContent parameter in OpenAI-to-Gemini transformation#5605
fix: forward cachedContent parameter in OpenAI-to-Gemini transformation#5605colegottdank wants to merge 1 commit intomainfrom
Conversation
- Add cachedContent field to GeminiGenerateContentRequest interface - Forward cachedContent from OpenAI-format requests to Gemini native format - Support both Vertex AI format (projects/*/locations/*/cachedContents/*) and Google AI Studio format (cachedContents/*) This fixes explicit caching not working when users pass cachedContent through the AI Gateway with OpenAI-compatible requests. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
Claude finished @colegottdank's task —— View job PR Review Complete ✅Score: 9/10 - Excellent implementation with comprehensive tests, no critical issues found Code Review AnalysisChanges Overview:
✅ Strengths
🔍 Code Quality AssessmenttoGoogle.ts:111-117 - The implementation is solid: const cachedContent = (openAIBody as any).cachedContent;
if (typeof cachedContent === "string" && cachedContent.length > 0) {
geminiBody.cachedContent = cachedContent;
}
google.ts:73-85 - Interface definition is well-documented: /**
* Reference to a cached content resource.
* Format: "projects/{project}/locations/{location}/cachedContents/{cache_id}"
* or "cachedContents/{cache_id}" for Google AI Studio
*/
cachedContent?: string;💡 Minor SuggestionConsider using explicit typing instead of // Current
const cachedContent = (openAIBody as any).cachedContent;
// Suggested (if feasible)
const cachedContent = (openAIBody as HeliconeChatCreateParams & { cachedContent?: string }).cachedContent;However, this change isn't critical since the current approach works correctly and maintains backward compatibility. 🚀 Impact Assessment
RecommendationApprove and merge - This is a well-implemented fix that solves a real cost-optimization problem with proper test coverage and no breaking changes. |
Summary
cachedContentfield toGeminiGenerateContentRequestinterfacecachedContentfrom OpenAI-format requests to Gemini native formatprojects/*/locations/*/cachedContents/*) and Google AI Studio format (cachedContents/*)Problem
When users send requests through the AI Gateway with explicit caching:
{ "model": "gemini-3-flash-preview/vertex", "messages": [{"role": "user", "content": "Analyze the data in the cache."}], "cachedContent": "projects/YOUR_PROJECT/locations/us-central1/cachedContents/YOUR_CACHE_ID" }The
cachedContentparameter was being dropped during the OpenAI-to-Gemini transformation, causing:Solution
The
toGoogle()transformation function now forwards thecachedContentparameter to the native Gemini request format.Test plan
🤖 Generated with Claude Code