Universal LLM Format Converter - Seamlessly convert between OpenAI, Anthropic, and Gemini API formats using a brand-neutral intermediate representation (IR).
- Unified Interface: Single API for all major LLM providers (OpenAI, Anthropic, Gemini)
- Bidirectional Conversion: Convert requests and responses between any two providers
- Type-Safe: Built with Pydantic for runtime validation and type safety
- Streaming Support: Full streaming event conversion for real-time applications
- Multimodal: Supports text, images, tool calls, and reasoning content
- Extensible: Easy to add new providers or custom adapters
pip install transllmgit clone https://github.com/transllm/transllm.git
cd transllm
pip install -e .git clone https://github.com/transllm/transllm.git
cd transllm
pip install -e ".[dev]"Convert an OpenAI request to Anthropic format:
from transllm.converters.request_converter import RequestConverter
# OpenAI format request
openai_request = {
"model": "gpt-4",
"messages": [
{"role": "user", "content": "Hello, Claude!"}
],
"temperature": 0.7,
}
# Convert to Anthropic format
converter = RequestConverter()
anthropic_request = converter.convert(openai_request, "openai", "anthropic")
# Use with Anthropic API
# result = anthropic_client.messages.create(**anthropic_request)from transllm.converters.response_converter import ResponseConverter
# Convert Anthropic response to OpenAI format
converter = ResponseConverter()
openai_response = converter.convert(anthropic_response, "anthropic", "openai")
# Use with OpenAI-compatible clients
# print(openai_response["choices"][0]["message"]["content"])from transllm.adapters import ProviderRegistry
adapter = ProviderRegistry.get_adapter("openai")
# Convert streaming event to unified IR
unified_event = adapter.to_unified_stream_event(openai_sse_event)
# Convert back to target provider format
target_event = adapter.from_unified_stream_event(unified_event)| Provider | Request Conversion | Response Conversion | Streaming | Multimodal | Tools |
|---|---|---|---|---|---|
| OpenAI | โ Full | โ Full | โ | โ | โ |
| Anthropic | โ Full | โ Full | โ | โ | โ |
| Gemini | โ Full | โ Full | โ | โ | โ |
- Text messages
- System instructions
- Tool calls and results
- Image content (multimodal)
- Reasoning content (OpenAI o1 series)
- Extended thinking (Anthropic)
temperature,top_p,top_kmax_tokens,max_completion_tokensstop_sequencesstreamseedpresence_penalty,frequency_penaltylogprobs,top_logprobsresponse_format- And more...
- Content deltas
- Tool call events
- Content completion
- Stream termination
- Metadata updates
TransLLM guarantees perfect idempotency:
# Original โ IR โ Original = Original
openai_req = {"model": "gpt-4", "messages": [...]}
ir_req = converter.to_unified(openai_req, "openai")
roundtrip_req = converter.from_unified(ir_req, "openai")
assert openai_req == roundtrip_req # โ
Always trueThis ensures zero information loss in conversions.
Run the test suite:
# All tests
pytest
# Specific provider tests
pytest tests/test_idempotency_openai.py
pytest tests/test_idempotency_anthropic.py
pytest tests/test_idempotency_gemini.py
# Cross-format conversion tests
pytest tests/test_cross_format_conversion.py
# Streaming tests
pytest tests/test_streaming_anthropic.pyCreate a custom adapter for a new provider:
from transllm.core.base_adapter import BaseAdapter
class CustomProviderAdapter(BaseAdapter):
def to_unified_request(self, data):
# Convert provider-specific request to IR
pass
def from_unified_request(self, unified_request):
# Convert IR to provider-specific request
pass
# ... implement other methodsRegister your adapter:
from transllm.utils.provider_registry import ProviderRegistry
ProviderRegistry.register("custom", CustomProviderAdapter)We welcome contributions! Please see CONTRIBUTING.md for guidelines.
git clone https://github.com/transllm/transllm.git
cd transllm
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black src tests
isort src tests
# Type checking
mypy srcThis project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by the need for LLM provider interoperability
- Built with Pydantic for type safety
- Thanks to all contributors and the open-source community
Please use GitHub Issues to report bugs or request features.
Current Version: 0.1.0 (Beta)
Test Coverage: 100% for core functionality
Supported APIs:
- OpenAI Chat Completions (all versions)
- Anthropic Messages API (all versions)
- Google Gemini (v1 and v2 series)
- Conversion time: < 1ms for typical requests
- Memory overhead: Minimal (no caching by default)
- Thread-safe: Yes
- Additional provider adapters (Mistral, Cohere, Groq, etc.)
- Enhanced grounding support
- Async adapter support
- Batch conversion utilities
- Response caching layer
- WebSocket streaming support
Made with โค๏ธ by the TransLLM team
For questions or support, join our Discord or open an issue.