Skip to content
This repository was archived by the owner on Apr 30, 2026. It is now read-only.
This repository was archived by the owner on Apr 30, 2026. It is now read-only.

[Feature Request] Add @llamaindex/openrouter LLM provider package #2262

Description

@alex129

[Feature Request] Add @llamaindex/openrouter LLM provider package

Feature Description

LlamaIndex Python has a dedicated llama-index-llms-openrouter package that provides first-class OpenRouter integration, allowing users to easily access 300+ LLM models through a single, unified API. However, LlamaIndex.TS currently has no equivalent package.

The TypeScript repo supports providers like OpenAI, Anthropic, Groq, Mistral, Fireworks, DeepSeek, Replicate, Together, HuggingFace, DeepInfra, and Gemini — but OpenRouter is missing.

Why OpenRouter?

OpenRouter acts as a unified gateway to hundreds of models (OpenAI, Anthropic, Google, Meta, Mistral, DeepSeek, and many more) through a single API key and a standardized OpenAI-compatible API. This is especially valuable for:

  • Developers who want model flexibility without managing multiple API keys and provider-specific packages.
  • Cost optimization — OpenRouter routes to the cheapest provider for a given model automatically.
  • Fallback/redundancy — automatic failover between providers if one is down.
  • Access to open-source models that aren't directly available through other LlamaIndex.TS providers.

Python parity

In Python, the integration is straightforward:

from llama_index.llms.openrouter import OpenRouter

llm = OpenRouter(
    api_key="<your-api-key>",
    max_tokens=256,
    context_window=4096,
    model="anthropic/claude-sonnet-4",
)
response = llm.complete("Hello World!")

There is no equivalent in LlamaIndex.TS today.

Proposed Solution

Create a new @llamaindex/openrouter package that:

  1. Wraps the OpenRouter API (which is OpenAI-compatible, so it could potentially extend @llamaindex/openai with a custom baseURL).
  2. Supports chat, complete, and their streaming variants.
  3. Exposes OpenRouter-specific features such as:

Desired API (example)

import { OpenRouter } from "@llamaindex/openrouter";

const llm = new OpenRouter({
  apiKey: "<your-api-key>",
  model: "anthropic/claude-sonnet-4",
  maxTokens: 256,
});

const response = await llm.complete({ prompt: "Hello World!" });

Workaround

Currently, users can hack around this by using @llamaindex/openai with a custom baseURL pointed at https://openrouter.ai/api/v1, but this is undocumented, fragile, and doesn't expose OpenRouter-specific features like provider routing or cost headers.

Additional Context

  • OpenRouter's own docs list LlamaIndex as a [supported framework](https://openrouter.ai/docs/guides/community/frameworks-and-integrations-overview) for both Python and TypeScript, but the TypeScript integration doesn't actually exist as a dedicated package.
  • The Python package source can serve as reference: llama-index-llms-openrouter on PyPI.
  • Since OpenRouter is OpenAI-compatible, the implementation effort should be relatively low — likely extending the existing OpenAI provider with a custom base URL and additional config options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions