llm-bridge-core 0.2.1

Protocol transform library for LLM API translation between Anthropic and OpenAI.
Documentation
llm-bridge-core-0.2.1 has been yanked.

llm-bridge-core

Protocol transform library for LLM API translation between Anthropic and OpenAI.

crates.io docs.rs 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

[dependencies]
llm-bridge-core = "0.2"

Quick Start

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

Anthropic Messages API OpenAI Chat Completions OpenAI Responses API
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

License

MIT