Metadata-Version: 2.5
Name: langchain-oathbreaker
Version: 0.1.0
Summary: LangChain chat model for Oathbreaker AI: abliterated GLM, DeepSeek and Kimi models through a prepaid, OpenAI-compatible API.
Project-URL: Homepage, https://oathbreaker.ai
Project-URL: Documentation, https://oathbreaker.ai/docs
Project-URL: Repository, https://github.com/Oathbreaker-AI/langchain-oathbreaker
Project-URL: Issues, https://github.com/Oathbreaker-AI/langchain-oathbreaker/issues
Project-URL: Changelog, https://github.com/Oathbreaker-AI/langchain-oathbreaker/blob/main/CHANGELOG.md
Author-email: "Oathbreaker (Formacha LLC)" <support@oathbreaker.ai>
Maintainer-email: "Oathbreaker (Formacha LLC)" <support@oathbreaker.ai>
License-Expression: MIT
License-File: LICENSE
Keywords: abliterated,chat-model,deepseek,glm,kimi,langchain,langgraph,llm,oathbreaker,openai-compatible
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: <4.0,>=3.11
Requires-Dist: langchain-core<2.0.0,>=1.8.5
Requires-Dist: langchain-openai<2.0.0,>=1.8.5
Description-Content-Type: text/markdown

# langchain-oathbreaker

A LangChain chat model for [Oathbreaker AI](https://oathbreaker.ai), a prepaid model API that serves abliterated GLM, DeepSeek and Kimi models through an OpenAI-style Chat Completions endpoint, with streaming, tool calling and reasoning.

```sh
pip install -U langchain-oathbreaker
export OATHBREAKER_API_KEY="your-api-key"
```

```python
from langchain_oathbreaker import ChatOathbreaker

model = ChatOathbreaker(model="oathbreaker-glm-5.3", max_tokens=2048)
print(model.invoke("Reply with exactly: Oathbreaker connected.").content)
```

[Create an account](https://oathbreaker.ai/sign-up), add prepaid credit and create a key in your [dashboard](https://oathbreaker.ai/dashboard). Every request is billed per token at the rates on the [pricing page](https://oathbreaker.ai/pricing).

## Why not `ChatOpenAI` with a base URL

`ChatOpenAI(base_url="https://oathbreaker.ai/v1", ...)` works for a plain call. The API accepts a [fixed list of request fields](https://oathbreaker.ai/docs#requests) and refuses a request that carries any other, and LangChain adds such fields in ordinary use. This class sends what the API accepts.

| Situation | `ChatOpenAI` with a base URL | `ChatOathbreaker` |
|---|---|---|
| A message has a `name`, as every message from a named LangGraph agent does | Refused: `unsupported field: name` | The name is left out |
| A chain or agent passes `stop` | Refused: `unsupported field: stop` | The answer is cut at the stop sequence (see [below](#stop-sequences)) |
| `seed`, `frequency_penalty`, `presence_penalty` or `user` is set | Refused | Left out, with a warning where it could matter |
| `bind_tools(..., strict=True)`, or an agent that asks for a response format beside tools | Refused: strict tools are not supported | Tools are sent without `strict` |
| The model's reasoning text | Dropped | Kept in `additional_kwargs["reasoning_content"]` and sent back with tool calls, as the API asks |
| `OPENAI_API_KEY`, `OPENAI_ORG_ID`, `OPENAI_PROJECT_ID` or `OPENAI_CUSTOM_HEADERS` is set | The organization, project and custom headers are sent to Oathbreaker. A missing Oathbreaker key falls back to the OpenAI key | Only `OATHBREAKER_API_KEY` is read, and nothing from the OpenAI settings is sent |
| A request fails | Repeated twice by default | Sent once (`max_retries=0`). A timeout does not show that nothing was charged |
| `get_num_tokens_from_messages`, used by `trim_messages` | Raises `NotImplementedError` | Returns an estimate |
| The request is too long for the model | A generic bad-request error | `ContextOverflowError`, which LangChain's summarization middleware recovers from |
| A streamed answer reaches its output limit in the middle of a tool call | LangChain fills in the end of the arguments, and an agent runs the tool with what arrived | `IncompleteToolCallError`, and the tool is not run |

## Models

| Model | Context window | Max output |
|---|---|---|
| `oathbreaker-glm-5.3` | 131,072 tokens | 32,768 |
| `oathbreaker-glm-5.3-flash` | 131,072 tokens | 32,768 |
| `oathbreaker-deepseek-v4.1-flash` | 65,536 tokens | 32,768 |
| `oathbreaker-deepseek-v4.1-flash-fast` | 65,536 tokens | 32,768 |
| `oathbreaker-kimi-k3.1-pro` | 524,288 tokens | 24,576 |

These are the values `GET https://oathbreaker.ai/v1/models` reports, which needs no key. Input and requested output share the window, and the output budget includes reasoning. The class passes these limits to LangChain as the model's profile. A model added after this release works too; LangChain then assumes nothing about its limits.

## Streaming

```python
for chunk in model.stream("Explain abliteration in two sentences."):
    print(chunk.text, end="", flush=True)
```

The last chunk carries `usage_metadata` for the whole request. `ainvoke`, `astream` and `batch` work as on any LangChain chat model. The API runs at most 10 generations at once per account and starts at most 60 a minute, so give `batch` a limit: `model.batch(prompts, config={"max_concurrency": 5})`.

## Tool calling

```python
from langchain_core.tools import tool


@tool
def get_weather(city: str) -> str:
    """Get the current weather in a city."""
    return f"It is 21 degrees and sunny in {city}."


model_with_tools = model.bind_tools([get_weather])
message = model_with_tools.invoke("What is the weather in Lisbon?")
print(message.tool_calls)
```

The API returns tool calls and does not run your tools. It does not enforce tool schemas either, so check the arguments before you act on them; a LangChain tool validates its own. Hosted tools such as web search are not offered.

An answer that reaches its output limit while the model is still writing a tool call raises `IncompleteToolCallError`, streamed or not, and the call is not passed on. The [API reference](https://oathbreaker.ai/docs#streaming) says never to run an incomplete tool call. Raise `max_tokens`, or lower `reasoning_effort`, because reasoning counts towards the same limit.

Agents work the same way (`pip install langchain`):

```python
from langchain.agents import create_agent

agent = create_agent(model, tools=[get_weather])
state = agent.invoke({"messages": [{"role": "user", "content": "What is the weather in Lisbon?"}]})
print(state["messages"][-1].content)
```

## Structured output

```python
from pydantic import BaseModel, Field


class Capital(BaseModel):
    """The capital of a country."""

    country: str = Field(description="The country asked about")
    capital: str = Field(description="Its capital city")


structured = model.with_structured_output(Capital)
print(structured.invoke("What is the capital of Portugal?"))
```

By default the schema is bound as a tool that the model must call, and Pydantic checks the result. `method="json_schema"` sends the schema as `response_format` instead, and `method="json_mode"` asks for a JSON object. With those two the API passes the request on to the model and does not check the answer, so a reply that does not fit the schema raises a parsing error; pass `include_raw=True` to get the error back instead.

## Reasoning

Every model reasons before it answers, and reasoning cannot be turned off. Set how much with `reasoning_effort`: `"low"`, `"high"` or `"max"`.

```python
model = ChatOathbreaker(model="oathbreaker-glm-5.3", max_tokens=8192, reasoning_effort="high")
message = model.invoke("How many prime numbers are there below 100?")
print(message.additional_kwargs["reasoning_content"])
print(message.content)
```

Reasoning and the answer share `max_tokens`. If reasoning uses the budget up, `response_metadata["finish_reason"]` is `"length"` and the content can be empty, so set `max_tokens` with room for both. The API uses 8,192 when you set none. Reasoning tokens are billed as output and reported in `usage_metadata["output_token_details"]["reasoning"]`.

## Stop sequences

The API has no stop sequences. When `stop` is passed, on the model or on a call, this class cuts the answer at the first stop sequence after it arrives, for streamed answers too. The model does not stop early: it writes its whole answer, and the account pays for all of it. `max_tokens` limits how much that can be. Agents that use tool calling need no stop sequences.

## What happens to settings the API does not take

| Setting | What this class does |
|---|---|
| `name` on a message, `user`, `metadata`, `store`, `service_tier` | Left out |
| `seed`, `frequency_penalty`, `presence_penalty`, `logit_bias` and any other field the API does not list | Left out, with an `OathbreakerWarning` |
| `strict=True` on tools | Tools are sent without `strict`, with an `OathbreakerWarning` if you asked for it yourself |
| `stop` | Applied to the answer after it arrives, with an `OathbreakerWarning` about the cost |
| `n` above 1, `logprobs`, the old `functions` format, images, audio and files in messages | `UnsupportedByOathbreaker`, raised before anything is sent |
| `reasoning={"effort": ...}` | Sent as `reasoning_effort` |
| `use_responses_api=True` | `ValueError` when the model is created. This class uses Chat Completions |

Python shows each warning once. To silence them, or to make them errors while you test:

```python
import warnings
from langchain_oathbreaker import OathbreakerWarning

warnings.simplefilter("ignore", OathbreakerWarning)  # or "error"
```

## Settings

| Setting | Default | Notes |
|---|---|---|
| `model` | required | One of the models above |
| `api_key` | `OATHBREAKER_API_KEY` | Creating the model without a key raises `ValueError` |
| `base_url` | `OATHBREAKER_BASE_URL`, then `https://oathbreaker.ai/v1` | The host is `oathbreaker.ai`, with no `api.` subdomain |
| `max_tokens` | none; the API uses 8,192 | Covers reasoning and the answer. A value above the model's maximum is lowered to it |
| `reasoning_effort` | none; the API chooses | `"low"`, `"high"` or `"max"` |
| `temperature`, `top_p` | none | 0 to 2, and 0 to 1 |
| `timeout` | `650` | Seconds. A generation can run for up to ten minutes |
| `max_retries` | `0` | [Check usage](https://oathbreaker.ai/docs#errors) before you repeat a request that timed out |
| `http_client`, `http_async_client` | none | For a proxy, pass `openai.DefaultHttpxClient(proxy=...)` and `openai.DefaultAsyncHttpxClient(proxy=...)` |

Errors are the OpenAI SDK's: `openai.AuthenticationError` for a wrong key, `openai.RateLimitError` for a rate limit, and `openai.APIStatusError` with `status_code == 402` when the account has no credit. The API's own message and `request_id` are in the error.

## Not offered

- **Embeddings.** Oathbreaker serves chat models only. For retrieval, take the embedding model from another provider.
- **Images, audio and files.** The models read and write text.
- **The Responses API through this class.** Oathbreaker has a Responses endpoint for Codex; this class always uses Chat Completions.

## Tests

```sh
uv sync --group test
uv run pytest
```

The unit tests run against a local stand-in for the API (`tests/unit_tests/mock_api.py`) that refuses what the API reference says the API refuses. They never leave your computer, and they say nothing about model quality or speed.

```sh
uv run pytest tests/integration_tests/test_model_list.py
OATHBREAKER_API_KEY="your-api-key" uv run pytest tests/integration_tests
```

The first command compares the model table with the live model list; it needs no key and costs nothing. The second sends real requests, including LangChain's standard integration tests, and **spends credit**.

Checked with `langchain-core` 1.8.5, `langchain-openai` 1.8.5, `langchain` 1.5.2 and `openai` 3.61.0 on Python 3.12.

## License

MIT. Oathbreaker AI is operated by Formacha LLC. Oathbreaker operates the API and billing, not the development of the underlying models.
