# llm-bridge-core
Protocol transform library for LLM API translation between Anthropic and OpenAI.
[](https://crates.io/crates/llm-bridge-core)
[](https://docs.rs/llm-bridge-core)
[](LICENSE)
## Overview
`llm-bridge-core` is a Rust library that translates request payloads, response payloads, and streaming SSE events between the Anthropic Messages API and OpenAI-compatible APIs (Chat Completions and Responses). It is a library-first, protocol-only component with no gateway concerns.
## Features
- **Anthropic → OpenAI**: Convert Messages API requests to Chat Completions or Responses format
- **OpenAI → Anthropic**: Convert Chat Completions / Responses requests back to Messages API format
- **Streaming**: Cross-protocol SSE → SSE translation with cross-chunk state management
- **Thinking**: Anthropic thinking blocks ↔ OpenAI reasoning content translation
- **Tool use**: Cross-protocol tool call / tool result translation with semantic equivalence
- **Streaming headers**: Automatic `content-type` detection and `x-no-response-completion` handling
## Installation
```toml
[dependencies]
llm-bridge-core = "0.2"
```
## Quick Start
```rust
use llm_bridge_core::transform;
// Convert an Anthropic Messages API request to OpenAI Chat Completions format
let openai_body = transform::anthropic_to_openai(anthropic_json_value)?;
// Convert an OpenAI response stream back to Anthropic format
let anthropic_body = transform::openai_to_anthropic(openai_json_value)?;
```
## Protocol Translation Matrix
| `messages` (user/assistant) | `messages` (role-based) | `input` array |
| `system` / `system_prompt` | `messages` with `system` role | `instructions` |
| `thinking` blocks | `reasoning` content | `reasoning` content |
| `tool_use` / `tool_result` | `tool_calls` / `tool` messages | `tool_calls` / `tool` messages |
| SSE: `message_start`, `content_block_delta`, `message_delta` | SSE: `choices[0].delta` | SSE: `response.output[*].content[*].delta` |
Unsupported fields are logged before omission rather than silently dropped.
## Crate Structure
```
crates/core/src/
├── lib.rs # Public API exports
├── config.rs # Runtime configuration
├── error.rs # Error types (thiserror-based)
├── types.rs # Shared type definitions
├── transform.rs # Protocol translation core
└── tests/
├── fixtures/ # Real API payload fixtures
└── e2e.rs # End-to-end streaming tests
```
## Documentation
- API docs: [docs.rs/llm-bridge-core](https://docs.rs/llm-bridge-core)
- Project docs: [specs/index.md](https://github.com/TokenFleet-AI/llm-bridge-rust/tree/master/specs), [docs/index.md](https://github.com/TokenFleet-AI/llm-bridge-rust/tree/master/docs)
- Server: [apps/server](https://github.com/TokenFleet-AI/llm-bridge-rust/tree/master/apps/server)
## License
MIT