llamaIndex - ✅(Solved) Fix [Bug]: OpenAILike does not work with Gemini API [1 pull requests, 4 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
run-llama/llama_index#20784Fetched 2026-04-08 00:30:59
View on GitHub
Comments
4
Participants
3
Timeline
10
Reactions
0
Timeline (top)
commented ×4cross-referenced ×2labeled ×2mentioned ×1

Fix Action

Fixed

PR fix notes

PR #20948: Fix OpenAILike Gemini OpenAI compatibility

Description (problem / solution / changelog)

Ensure OpenAILike routes Gemini OpenAI-compatible endpoints through the Chat Completions API so that Gemini models no longer return 404 when used via OpenAILike.

This change auto-detects Gemini's OpenAI compatibility base URL and defaults is_chat_model to True in that case.

Closes #20784.

Changed files

  • llama-index-integrations/llms/llama-index-llms-openai-like/llama_index/llms/openai_like/base.py (modified, +19/-2)
  • llama-index-integrations/llms/llama-index-llms-openai-like/tests/test_openai_like.py (modified, +25/-0)

Code Example

llm = OpenAILike(
    model=LLM_MODEL, # Gemini Model
    api_key=LLM_API_KEY, # Gemini API Key
    api_base=LLM_BASE_URL, # `https://generativelanguage.googleapis.com/v1beta/openai/` as guideline in Gemini API OpenAI compatibility
)

---
RAW_BUFFERClick to expand / collapse

Bug Description

OpenAILike does not work with Gemini API

Version

0.14.15

Steps to Reproduce

llm = OpenAILike(
    model=LLM_MODEL, # Gemini Model
    api_key=LLM_API_KEY, # Gemini API Key
    api_base=LLM_BASE_URL, # `https://generativelanguage.googleapis.com/v1beta/openai/` as guideline in Gemini API OpenAI compatibility
)

Relevant Logs/Tracbacks

stacktrace.log

extent analysis

<think> Okay, let's see. The user is trying to use the OpenAILike class with the Gemini API, but it's not working. They mentioned they're using version 0.14.15. The steps to reproduce show they're setting up the OpenAILike with a model, API key, and a base URL that's supposed to be compatible with Gemini's OpenAI compatibility.

Hmm, the problem is likely due to the base URL not being correctly formatted. The Gemini API's OpenAI compatibility might require a different endpoint structure. The user provided a base URL ending with 'openai/', but maybe it should be 'chat/completions' instead. Also, the model name might need to be specified differently for Gemini.

Another thing is the API key. The user is using a Gemini API key, but the OpenAILike class might expect an OpenAI-style API key. Wait, but the base URL is supposed to route to Gemini. Maybe the headers or the request format are different. The OpenAILike class might not handle the specific response format from Gemini, leading to errors.

So the fix would involve adjusting the base URL to the correct endpoint, ensuring the model name is correct, and possibly adding necessary headers. Also, checking if the API key is being passed correctly. Let me look up the correct Gemini OpenAI compatibility URL. Oh right, the correct base URL should be 'https://generativelanguage.googleapis.com/v1beta/openai/chat/completions' maybe. Also, the model parameter might need to be 'gemini-pro' or similar.

The user's code example shows the base URL as 'https://generativelanguage.googleapis.com/v1beta/openai/'. The correct path should include 'chat/completions' for the endpoint. So the base URL should be adjusted to point to that. Then, the model name should be set to the appropriate Gemini model. Also, maybe the API key needs to be in the

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

llamaIndex - ✅(Solved) Fix [Bug]: OpenAILike does not work with Gemini API [1 pull requests, 4 comments, 3 participants]