Skip to content

Add LiteLLM AI gateway provider for LLM and embeddings#545

Open
RheagalFire wants to merge 2 commits into
neo4j:mainfrom
RheagalFire:feat/add-litellm-provider
Open

Add LiteLLM AI gateway provider for LLM and embeddings#545
RheagalFire wants to merge 2 commits into
neo4j:mainfrom
RheagalFire:feat/add-litellm-provider

Conversation

@RheagalFire

Copy link
Copy Markdown

Description

Add LiteLLM as an LLM and embeddings provider, giving users access to 100+ LLM providers (OpenAI, Anthropic, Google, Azure, AWS Bedrock, Ollama, Cohere, Mistral, and more) through a single unified interface.

What's included:

  • LiteLLMChat LLM provider (src/neo4j_graphrag/llm/litellm_llm.py) - supports both V1 (string input) and V2 (message list input) interfaces, structured output via response_format, and tool calling
  • LiteLLMEmbeddings embeddings provider (src/neo4j_graphrag/embeddings/litellm.py) - sync and async embedding generation
  • Optional dependency: pip install "neo4j-graphrag[litellm]" (litellm>=1.80.0,<1.87.0)
  • 23 unit tests covering both providers

Usage:

from neo4j_graphrag.llm import LiteLLMChat
from neo4j_graphrag.embeddings import LiteLLMEmbeddings

# Use any LiteLLM-supported model
llm = LiteLLMChat(model_name="gpt-4o", api_key="...")
llm = LiteLLMChat(model_name="anthropic/claude-sonnet-4-20250514", api_key="...")
llm = LiteLLMChat(model_name="ollama/llama3")

response = llm.invoke("Hello!")

# Embeddings
embedder = LiteLLMEmbeddings(model="text-embedding-ada-002", api_key="...")
vector = embedder.embed_query("Some text")

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Documentation update
  • Project configuration change

Complexity

Complexity: Low

How Has This Been Tested?

  • Unit tests
  • E2E tests
  • Manual tests

Manual testing performed with Azure Anthropic Foundry endpoint confirming V1 sync, V2 sync, and async invoke all work correctly with real API calls.

Checklist

The following requirements should have been met (depending on the changes in the branch):

  • Documentation has been updated
  • Unit tests have been updated
  • E2E tests have been updated
  • Examples have been updated
  • New files have copyright header
  • CLA (https://neo4j.com/developer/cla/) has been signed
  • CHANGELOG.md updated if appropriate

Signed-off-by: RheagalFire <arishalam121@gmail.com>
@RheagalFire RheagalFire requested a review from a team as a code owner June 16, 2026 18:56
):
call_kwargs["response_format"] = {
"type": "json_schema",
"json_schema": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"strict": True is missing in json_schema

Comment thread src/neo4j_graphrag/llm/litellm_llm.py Outdated
llm = LiteLLMChat(model_name="ollama/llama3")
"""

supports_structured_output = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not all providers support structured output.

else:
raise ValueError(f"Invalid input type for ainvoke method - {type(input)}")

def invoke_with_tools(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lacks rate limit handling

content=res.choices[0].message.content,
)

async def ainvoke_with_tools(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lacks rate limit handling



# pylint: disable=redefined-builtin, arguments-differ, raise-missing-from, no-else-return, import-outside-toplevel
class LiteLLMChat(LLMBase):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Docs page is missing for this provider

# See the License for the specific language governing permissions and
# limitations under the License.

# Generated by Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't be committed!

- Add "strict": True to json_schema response_format in _invoke_v2 and
  _ainvoke_v2, matching the OpenAI provider pattern
- Set supports_structured_output = False since not all LiteLLM-supported
  providers handle structured output
- Add @rate_limit_handler_decorator to invoke_with_tools and
  @async_rate_limit_handler_decorator to ainvoke_with_tools for
  consistent rate limit handling across all methods
- Add LiteLLM provider documentation to user guide and API reference
- Remove "Generated by Claude Code" comments from test files
@RheagalFire RheagalFire force-pushed the feat/add-litellm-provider branch from dd1905f to e17683f Compare July 1, 2026 19:16
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.

2 participants