Skip to main content

LangExtract provider plugin for OpenRouter API

Project description

LangExtract OpenRouter Provider

A LangExtract provider plugin for OpenRouter.

Installation

# Using uv (recommended)
uv pip install langextract-provider-openrouter

# Or using pip
pip install langextract-provider-openrouter

Quick Start

  1. Set your OpenRouter API key:

    export OPENROUTER_API_KEY=your_key_here
    
  2. Use it in LangExtract:

    import langextract as lx
    
    # Use the 'openrouter/' prefix followed by the OpenRouter model ID
    result = lx.extract(
        text_or_documents="...",
        prompt_description="...",
        model_id="openrouter/google/gemini-3-flash-preview"
    )
    

Supported Models

This provider supports any model available on OpenRouter by prefixing the model ID with openrouter/. Common examples include:

  • openrouter/google/gemini-3-flash-preview
  • openrouter/google/gemini-3-pro-preview
  • openrouter/google/gemini-2.5-flash-preview-09-2025
  • openrouter/Qwen/Qwen2.5-VL-72B-Instruct
  • openrouter/openai/gpt-5

Configuration Options

Customize your requests using the provider_options dictionary.

Reasoning Effort

Control the reasoning effort for models that support it.

# Create a model with high reasoning effort
config = factory.ModelConfig(
    model_id="openrouter/Qwen/Qwen2.5-VL-72B-Instruct",
    provider_kwargs={
        "provider_options": {
            "effort": "high"
        }
    }
)

Routing/Provider Options

These options control how OpenRouter acts as a router:

  • sort: Strategy for provider selection ("price", "latency", "throughput"). Default: "price".
  • ignore: List of provider names to exclude (e.g., ["Parasail"]).
  • allow_fallbacks: Boolean to allow falling back to other providers. Default: True.
  • data_collection: "allow" or "deny". Default: "allow".

Usage Example (Inference Override)

result = lx.extract(
    # ... inputs ...
    # Example: GPT-5
    model_id="openrouter/openai/gpt-5",
    provider_options={
        "effort": "medium",
        "sort": "throughput",
        "ignore": ["SlowProvider"]
    }
)

Development

cd langextract-openrouter
uv venv --python 3.12
# Install dependencies
uv pip install -e ../langextract
uv pip install -e .
uv pip install pytest requests
# Run tests
uv run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langextract_provider_openrouter-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file langextract_provider_openrouter-0.1.0.tar.gz.

File metadata

File hashes

Hashes for langextract_provider_openrouter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 517a5e6418c8d823a745e8e2100f7bf2714ab2dc4a4ecae84569f11308362b5b
MD5 4450898033bc62776651360e242454a1
BLAKE2b-256 a9d103879e93e83351d12c29cd53a7361e5b0cb6acab9a7832cace809f225666

See more details on using hashes here.

File details

Details for the file langextract_provider_openrouter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langextract_provider_openrouter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 152d47af05988a9584a8cc3b3747725d2082b1db7725f3ce67e4d1a506442586
MD5 f28a39235b48edf34fbbd62e91914719
BLAKE2b-256 102f6d9db394dfd99421cd39d560bea7b6a2fa715157f0307a494889a6f18896

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page