Metadata-Version: 2.4
Name: llm-babel
Version: 0.2.1
Summary: One transform spec, compiled to Python/Rust/TypeScript, translating LLM requests between provider formats.
License-Expression: MIT
License-File: LICENSE
Requires-Dist: pydantic>=2 ; extra == 'validation'
Requires-Python: >=3.10
Project-URL: Repository, https://github.com/pydantic/babel
Provides-Extra: validation
Description-Content-Type: text/markdown

# llm-babel

Translate an LLM request, response, error, or stream between provider wire formats, and get the
exact same result whether it runs in Python, Rust, or TypeScript.

Every provider speaks a slightly different dialect on the wire. `llm-babel` routes everything
through one neutral intermediate representation, so a format is one decoder plus one encoder
rather than a converter per pair. The transforms are authored once as a small pure spec and
compiled to plain Python, Rust, and TypeScript, proven byte-identical against a shared golden
corpus that ships in this package.

Formats: `openai-chat`, `openai-responses`, `anthropic-messages`, `bedrock-converse`, `gemini`,
`mistral`, `deepseek`, `cohere`, plus the OpenAI-compatible providers (Groq, Cerebras, xAI,
Z.AI, OpenRouter, HuggingFace) as routes over the `openai-chat` codec.

## Install

```bash
pip install llm-babel                # the runtime: pure stdlib, no dependencies
pip install "llm-babel[validation]"  # adds Pydantic for the typed, validating IR surface
```

The import name is `llm_transform`.

## Use

```python
from llm_transform.registry import translate, decode, encode

translate("openai-chat", "anthropic-messages", openai_request)  # source wire -> target wire
decode("gemini", gemini_request)                                # any wire -> IR
encode("bedrock-converse", ir)                                  # IR -> any wire
```

Responses, errors, and streams have the same shape of API (`translate_response`,
`translate_error`, `fold_stream`), and `reconcile` fits a request to a target's declared
capabilities before encoding.

Re-run the proof against the corpus shipped in the wheel:

```bash
python -m llm_transform.corpus.runner
```

The same transforms are published for TypeScript as `@pydantic/llm-babel` on npm.
