Metadata-Version: 2.5
Name: langchain-quickrouter
Version: 0.1.0
Summary: QuickRouter Chat Completions integration for LangChain Python.
Project-URL: Repository, https://github.com/YunSongMax/langchain-quickrouter
Project-URL: Documentation, https://github.com/YunSongMax/langchain-quickrouter#readme
Project-URL: Issues, https://github.com/YunSongMax/langchain-quickrouter/issues
License-Expression: MIT
License-File: LICENSE
Keywords: chat-completions,langchain,quickrouter
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: langchain-core<2,>=1.7.7
Requires-Dist: langchain-openai<2,>=1.7.4
Requires-Dist: pydantic<3,>=2.7.4
Provides-Extra: dev
Requires-Dist: build<2,>=1.3; extra == 'dev'
Requires-Dist: httpx<1,>=0.28; extra == 'dev'
Requires-Dist: mypy<3,>=1.19; extra == 'dev'
Requires-Dist: pytest<10,>=8.4; extra == 'dev'
Requires-Dist: ruff<1,>=0.14; extra == 'dev'
Requires-Dist: twine<8,>=6; extra == 'dev'
Description-Content-Type: text/markdown

# QuickRouter for LangChain Python

`langchain-quickrouter` provides `ChatQuickRouter`, a LangChain chat model for QuickRouter's OpenAI-compatible Chat Completions endpoint. It requires Python 3.10 or later.

## Install and configure

```sh
pip install langchain-quickrouter
```

Create an API key in the [QuickRouter console](https://api.quickrouter.ai/console/token) and set `QUICKROUTER_API_KEY` in your application's environment.

| Setting | Default |
| --- | --- |
| `model` | `claude-sonnet-5-5`. Pass any model ID enabled for your key. |
| `api_key` | Reads `QUICKROUTER_API_KEY`. Strings are converted to Pydantic `SecretStr`. |
| `base_url` | Reads `QUICKROUTER_API_BASE` and defaults to `https://api.quickrouter.ai/v1`. Keep `/v1` in the API base URL. |

An explicit argument takes precedence over its environment variable. If you override the base URL, use an endpoint you trust with your API key.

## Invoke a model

```python
from langchain_quickrouter import ChatQuickRouter

chat = ChatQuickRouter(max_tokens=64)
message = chat.invoke("Explain what an HTTP reverse proxy does in one sentence.")
print(message.text)
```

Use `await chat.ainvoke(...)` for asynchronous invocation.

## Stream a response

```python
from langchain_quickrouter import ChatQuickRouter

chat = ChatQuickRouter(model="deepseek-v4.1-flash", max_tokens=100)
for chunk in chat.stream("List two causes of an HTTP timeout."):
    if chunk.text:
        print(chunk.text, end="", flush=True)
```

## Bind tools

```python
from pydantic import BaseModel

from langchain_quickrouter import ChatQuickRouter


class Weather(BaseModel):
    """Look up weather by city."""

    city: str


chat = ChatQuickRouter()
with_tools = chat.bind_tools([Weather], tool_choice="Weather")
message = with_tools.invoke("Look up the weather in Oslo.")
print(message.tool_calls)
```

LangChain returns the requested tool name and arguments. Run the application tool separately when those inputs pass your application's checks. Use `with_structured_output(schema, method="json_schema")` on a model route that accepts native JSON Schema. Tool and structured output support vary by model and route.

## Model IDs

| Family | Example IDs |
| --- | --- |
| GPT | `gpt-6.2-astra`, `gpt-6.2-sol`, `gpt-6.1-terra` |
| Claude | `claude-opus-5-5`, `claude-fable-5-2`, `claude-sonnet-5-5`, `claude-haiku-5-5` |
| Gemini | `gemini-4-carbon`, `gemini-4-hydrogen`, `gemini-4-neon` |
| DeepSeek | `deepseek-v4.1-flash`, `deepseek-v4-pro` |
| Grok | `grok-4.7` |

`QUICKROUTER_MODELS` exports these examples. For current model availability, supported endpoints, and rates, see [QuickRouter pricing](https://quickrouter.ai/pricing).
