Metadata-Version: 2.5
Name: langchain-outrun
Version: 0.1.0
Summary: LangChain integration for Outrun, a prepaid OpenAI-compatible API for GPT, Claude, Gemini, DeepSeek and more
Project-URL: Homepage, https://outrun.to
Project-URL: Documentation, https://github.com/OutrunAIAPI/langchain-outrun#readme
Project-URL: Pricing, https://outrun.to/pricing
Project-URL: Repository, https://github.com/OutrunAIAPI/langchain-outrun
Project-URL: Issues, https://github.com/OutrunAIAPI/langchain-outrun/issues
Author-email: Outrun LLC <support@outrun.to>
License-Expression: MIT
License-File: LICENSE
Keywords: chat,langchain,llm,openai-compatible,outrun
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: <4.0,>=3.10
Requires-Dist: langchain-core<2.0.0,>=1.0.0
Requires-Dist: langchain-openai<2.0.0,>=1.0.0
Description-Content-Type: text/markdown

# langchain-outrun

LangChain integration for [Outrun](https://outrun.to), a prepaid, OpenAI-compatible API. One Outrun key reaches GPT, Claude, Gemini, Grok, DeepSeek, GLM, Kimi, Qwen and MiniMax models.

`ChatOutrun` is a LangChain chat model built on `langchain-openai`, with the Outrun base URL and key set for you.

## Install

```bash
pip install -U langchain-outrun
```

Create a key at https://outrun.to/key, then:

```bash
export OUTRUN_API_KEY="your-api-key"
```

## Chat model

```python
from langchain_outrun import ChatOutrun

model = ChatOutrun(model="gpt-5.6-terra", temperature=0)
print(model.invoke("Explain prompt caching in one sentence.").content)
```

Pick any model id from https://outrun.to/pricing (for example `claude-haiku-5-5`, `gemini-3.8-flash` or `deepseek-v4.1-flash`). The same list is available as JSON, without a key, at `https://api.outrun.to/pricing`.

### Streaming

```python
for chunk in model.stream("Write a haiku about rain."):
    print(chunk.text, end="", flush=True)
```

Token usage is included in streamed responses (`usage_metadata` on the last chunk).

### Tool calling

```python
from pydantic import BaseModel, Field


class GetWeather(BaseModel):
    """Get the current weather for a city."""

    city: str = Field(description="City name")


model_with_tools = model.bind_tools([GetWeather])
msg = model_with_tools.invoke("What's the weather in Paris?")
print(msg.tool_calls)
```

### Structured output

```python
class Answer(BaseModel):
    answer: str
    confidence: float


structured = model.with_structured_output(Answer)
print(structured.invoke("Is the sky blue? Answer briefly."))
```

Tool calling and structured output depend on the model you pick.

### Async

`ainvoke`, `astream` and `abatch` work as with any LangChain chat model.

## Settings

| Argument | Environment variable | Default |
|---|---|---|
| `api_key` | `OUTRUN_API_KEY` | none (required) |
| `base_url` | `OUTRUN_API_BASE` | `https://api.outrun.to/v1` |
| `model` | | none (required) |

Other `ChatOpenAI` arguments such as `temperature`, `max_tokens`, `timeout`, `max_retries` and `default_headers` work the same way.

- Requests go to `/v1/chat/completions`. Pass `use_responses_api=True` to use `/v1/responses` instead (GPT models only).
- `ChatOutrun` never reads `OPENAI_API_KEY`, so an OpenAI key is never sent to Outrun.
- Each request carries an `X-Outrun-SDK: langchain/<version>` header.

## Development

```bash
pip install -e . pytest pytest-asyncio pytest-socket "langchain-tests>=1,<2"
pytest tests/unit_tests --disable-socket --allow-unix-socket
```

`tests/integration_tests` call the live API (billed to your balance) and run only when `OUTRUN_API_KEY` is set.

## Links

- Outrun docs: https://outrun.to/docs/
- Plain OpenAI SDK wrapper: [`outrun-ai`](https://pypi.org/project/outrun-ai/)
- Support: support@outrun.to

License: MIT.
