Skip to main content
Protoverta logo

Protoverta

Universal LLM Protocol Adapter

Chat Completions <-> Messages <-> Responses

One Gateway. Any Protocol. Any Model.

Documentation MIT License Python 3.11+ Windows and Linux No dependencies CI Latest release

Protoverta converts requests and responses among OpenAI Chat Completions, Anthropic Messages, and OpenAI Responses. Use it as a Python library or run it as a local HTTP gateway.

Current scope: text, user images and inline PDF inputs, client-side function tools, forced function selection, and supported JSON output formats, including incremental SSE where usage and event ordering can be preserved. Optional policies support token counting, certified cache checkpoints and native Responses compaction. Unsupported fields, audio/video conversion and nonportable server-owned state are rejected rather than silently changed.

Ready-made launchers. To use Codex or Claude Code with another provider without configuring the gateway yourself, install one of the launchers built on Protoverta:

Launcher Runs Command
CodexApter OpenAI Codex CLI with Chat Completions, Messages or Responses providers codex-ca
ClaudApter Claude Code with Messages, Chat Completions or Responses providers claude-ca

Tested providers and their limits: provider compatibility.

Install

Python 3.11+ is required; there are no dependencies.

python -m pip install protoverta

Full documentation — guides, the gateway's HTTP API, the command reference and the Python API — is at haiancao.github.io/Protoverta. To work on Protoverta itself, see CONTRIBUTING.md.

Library

from protoverta import convert_request, convert_response

messages_request = {
    "model": "your-model-id",
    "max_tokens": 256,
    "messages": [{"role": "user", "content": "Hello"}],
}

chat_request = convert_request(messages_request, "messages", "chat")
# messages_response = convert_response(chat_response, "chat", "messages")

ConversionError indicates an unsupported or invalid JSON conversion. For SSE, StreamTranscoder accepts upstream bytes via feed() and requires finish() at EOF; it raises StreamError on invalid or interrupted streams. Protocol names are chat, messages, and responses.

Bare conversion APIs omit unknown tools/choice/parallel policy. Supply the original request via request_context to preserve known metadata in JSON/SSE. The HTTP gateway establishes and enforces its effective per-request tool policy; see Responses metadata for the contract and strict SDK limits.

top_p maps across all six request routes with explicit range/type validation; omitted values do not invent a sampling setting. Provider/model support remains subject to capability checks.

Image-bearing tool results map between Messages and Responses without changing their role or call ID. Explicit strict function flags map between Chat and Responses. Stop-sequence request controls map between Chat and Messages, but matched-stop response metadata remains nonportable; see the exact boundaries.

Completed JSON custom tools map directly between Chat and Responses, preserving raw input and text/grammar formats. Cross-protocol custom streaming and custom tools targeting Messages remain rejected. The gateway also offers opt-in client tool search via --client-tool-search function, including SSE with bounded per-call argument buffering; it does not execute searches or emulate hosted search. See custom tools and client search for the provider-support requirements and exact limits.

User images support URL/base64 references in ordered text/image messages on all six request routes. Explicit detail selectors, provider-owned file IDs and image tool results have portability limits; see image inputs.

Gateway

Provide credentials through environment variables:

$env:PROTOVERTA_UPSTREAM_KEY = "your-upstream-key"
$env:PROTOVERTA_LOCAL_TOKEN = "a-long-random-local-token"
python -m protoverta --upstream-protocol chat --upstream-base-url https://provider.example/v1 --upstream-key-env PROTOVERTA_UPSTREAM_KEY --inbound-token-env PROTOVERTA_LOCAL_TOKEN --port 8765

The gateway accepts POST /v1/chat/completions, POST /v1/messages, and POST /v1/responses. It binds to 127.0.0.1, prints its URL on startup, and requires Authorization: Bearer <local-token>. Use --auth-style x-api-key for upstreams that require that header.

--upstream-reasoning provider_default preserves client settings (the default). Choose disabled to override effort with none on Chat/Responses or disabled thinking on Messages. For OpenRouter, choose openrouter_disabled, which sends reasoning: {enabled: false} on Chat/Responses instead. These explicit overrides apply after conversion, also on native routes; they request disabling computation, not hiding reasoning output. Models requiring reasoning may reject them; the gateway does not retry with a different setting or discard unsupported output. The equivalent Python option is GatewayConfig(..., upstream_reasoning="openrouter_disabled").

--reasoning-output omit explicitly drops upstream reasoning that a translated route cannot represent (never fabricated or forwarded); the default reject fails instead. Many current models reason on every turn and reject or ignore a disable request, so the launchers' auto policy uses omit on translated routes. See the reasoning contract.

--public-reasoning separately opts into unsigned Chat reasoning_content ↔ Responses reasoning_text conversion for JSON/SSE and explicit history replay. It never turns summaries into raw reasoning, fabricates Messages signatures, or migrates encrypted state. See the reasoning contract.

Streaming supports all six directions for text and client-side function calls. Chat/Responses → Messages requires the explicit --messages-usage-policy deferred option (or StreamTranscoder(..., messages_usage_policy="deferred")). Initial usage is provisionally zero, then corrected with measured usage in message_delta; final input and output counts are mandatory. Overlapping tool calls are serialized in first-start order with bounded buffering. The default strict policy still rejects these two routes.

Native streams preserve feature payloads, including thinking/signatures, while validating framing and lifecycle. Successful terminal events are held until upstream EOF is verified. Cross-protocol conversion rejects unsupported content, annotations and interrupted streams. Explicitly requested text logprobs are supported between Chat and Responses; unrequested probability data remains an error. The upstream base URL is the exact API prefix: include /v1 or another version when required; Protoverta only appends the endpoint suffix. Native upstream API errors and allowed retry headers are preserved.

Usage normalizes total input tokens, including Messages cache reads and writes, and preserves reported cache/reasoning subtotals where the target can represent them. Unknown subtotals are omitted; measured zero remains zero. Strict Responses SDKs can reject incomplete usage details, including Messages → Responses because Messages does not report a reasoning-token subtotal. See SDK compatibility limits. Interim deferred usage is not accurate context accounting. Effort levels low, medium and high map between each API's effort option; models determine their effect and availability.

For Codex's stateless text/function subset, opt in with --client-profile codex. This policy omits client telemetry, cache hints and the encrypted-reasoning include hint. It requires reasoning summaries to be disabled, maps initial developer instructions to Messages system text, and accepts an explicit Messages fallback limit via --default-max-output-tokens. The developer-to-system mapping is a compatibility policy; the two roles do not have guaranteed identical instruction priority. Hosted tools and hidden reasoning replay remain unsupported. The default strict profile does not perform these client-specific adjustments.

--namespace-tools flatten explicitly converts Responses function namespaces to deterministic, collision-checked flat aliases for Chat/Messages. Each request rebuilds its own mapping from definitions and historical calls; JSON responses and SSE call items restore the original name and namespace, preserving call IDs and arguments. Namespace descriptions are prepended to function descriptions. Nested namespaces and custom/strict/hosted tools remain unsupported. An explicit gateway extension can select one declared namespaced function. The default is reject; native forwarding is unchanged. Use GatewayConfig(..., namespace_tools="flatten") from Python.

For long or nonportable ordinary function names, opt into --tool-names alias (tool_names="alias" in Python). Aliases are request-local and reversible for definitions, history, forced choice, JSON and SSE; native forwarding is unchanged. The explicit Codex/Claude compatibility profiles select aliasing by default; --tool-names reject overrides that choice. Standalone strict mode stays strict. See function-name and identity rules.

Forced function selection maps between all three protocols. JSON object mode maps between Chat and Responses; JSON Schema maps across the supported strict subset when Messages is involved. See tool selection and output formats.

An optional capability registry can block unsupported provider/model features before upstream I/O. Configure it with --capabilities-file FILE; add --require-verified-capabilities to reject unknown features too. Records are scoped to the exact API prefix, protocol and model.

Version-2 capability records can also declare output-token limits, context-window metadata and allowed reasoning efforts. Explicit incompatible budgets/efforts are rejected, not silently reduced. See the registry documentation for scope.

Optional runtime policies provide exact-model wire profiles, cross-process request budgets and bounded pre-response HTTP retries. These remain off unless explicitly configured; no model fallback or stream replay is introduced.

The gateway bounds active requests with --max-concurrent-requests (default 16) and socket I/O with --timeout (default 300 seconds; --progress-timeout 300 s and --total-timeout 3600 s bound idle and whole-request time). See failure mapping and resource limits.

For payload-free local request diagnostics, add --diagnostics. JSON lines go to stderr only; no log file is created. Each response has a fresh X-Protoverta-Request-ID. See diagnostics and privacy for supported fields and post-header SSE failure handling.

For a Messages model whose provider explicitly supports mid-conversation system text, opt in with repeatable --messages-system-model EXACT_MODEL_ID or GatewayConfig(..., messages_system_models=("EXACT_MODEL_ID",)). No model is enabled by default. Instructions stay in place and must follow a complete user turn (including all tool results) and precede assistant or end the array. The Codex profile maps developer text to system text only under this explicit policy; this does not make every Codex model-switch transcript valid. The library-level equivalent is convert_request(..., messages_mid_system=True) after capability verification. See the placement rules.

For Claude Code translation, use --client-profile claude --messages-usage-policy deferred. Disable thinking, experimental betas, structured output and tool search in the client before sending requests. The profile omits cache hints and client metadata, accepts the SDK's beta=true query marker without forwarding it to another protocol, and represents tool-result errors as explicitly labelled text. Thinking/signature blocks, compaction and hosted tools remain unsupported. Native Messages does not apply this profile's rewriting. See the streaming policy decision.

The Codex profile also omits validated whitespace-only assistant placeholders between a function call and its result when targeting Chat. Meaningful post-call text, annotations and unknown fields are not discarded; strict conversion without this client profile remains unchanged.

Contributing

PRs should include sanitized fixtures and tests for both directions of any protocol change. Never commit API keys or private conversations.

python -m pip install -e ".[test,typing]"
python -m pytest
python -m ruff check src tests sdk_tests scripts
python scripts/check_types.py

The strict type gate currently covers seventeen runtime/boundary modules, not every codec or launcher. See the typing scope.

For independent official-SDK stream tests, install the optional sdk-test extra and run python scripts/check_sdk.py. The gate uses only loopback fixtures and no provider keys; see conformance scope and findings.

Installed CLI clients can be exercised without provider keys. The smoke harness uses a loopback fixture, temporary client state and two read-only tool calls:

python scripts/smoke_clients.py --client codex --upstream chat --tool-loop
python scripts/smoke_clients.py --client claude --upstream messages --tool-loop
python scripts/smoke_clients.py --client claude --upstream chat --tool-loop
python scripts/smoke_clients.py --client claude --upstream responses --tool-loop

Use --adapter-source PATH to include a source launcher, or --installed-adapter to test a launcher installed in the active Python environment. These fixtures verify client/protocol interoperability, not a real provider's model capabilities.

Provider checks and limits: tested providers and known limits (OpenRouter, NVIDIA NIM, TokenHarbor, AgentRouter) and OpenRouter text/tool conformance. Session replay checks and boundaries: resume compatibility.

For an opt-in real OpenRouter text round trip through a source launcher, use scripts/probe_clients.py --client claude --upstream chat --model MODEL_ID --key-env KEY_VARIABLE --adapter-source PATH --allow-live. This uses temporary client state, explicitly disables upstream reasoning, and may incur API charges. Add --tool-loop to verify Claude's read-only nonce-file tool round trip, or Codex's read-only get_goal query with its matching tool result observed in the outbound request. Shell permissions are not relaxed. These probes do not test resume unless --resume-target is provided; never use private prompts as fixtures.

For a two-turn real resume probe, use --resume-target PROTOCOL. Combine it with --tool-loop to resume after a completed read-only tool call. The selected model is retained, while the second invocation uses a different provider configuration ID and must recall a token from the first turn. This still requires --allow-live and may incur API charges.

See SECURITY.md for reporting security issues. Licensed under MIT.

Optional gateway controls: exact route evidence, bounded model catalogs, and context preflight / local soak.

Provider integration: declarative profiles, route doctor and session diagnostics. Extended contracts: token counting, prompt caching, PDF and native compaction. Operational contracts: HTTP boundaries and count errors, explicit routing and token quotas. Development evidence: versioned validation matrix and current OpenResponses schema gaps. Latest local source/wheel acceptance: P14 results and remaining gates. Isolated acceptance: local preview, harness tools and session MCP.

Metadata

Release files for protoverta 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for protoverta 0.4.0
File Size Uploaded Provenance Actions
protoverta-0.4.0.tar.gz 698.6 kB With provenance Details for protoverta-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for protoverta 0.4.0
File Interpreter ABI Platform Actions
protoverta-0.4.0-py3-none-any.whl Python 3 none any Details for protoverta-0.4.0-py3-none-any.whl

Total release size: 854.1 kB

Release files / protoverta-0.4.0.tar.gz

Download URL protoverta-0.4.0.tar.gz
Size 698.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e1c3bc003434b5071d98d3b243bebaff0dda4c216e048c8d78a1e59038859d55
BLAKE2b-256 checksum
How to use checksums
8f403776641865d9e07a72c1afc1c3ad4dd4875ec4856b400837d11a82a86141
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / protoverta-0.4.0-py3-none-any.whl

Download URL protoverta-0.4.0-py3-none-any.whl
Size 155.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14aba71545b4689c10823fa5b6cde75f2af08d744c6942687a26f447c69ac5cd
BLAKE2b-256 checksum
How to use checksums
db766083c1cd46824afc09cd70161cc6f92824d9a5c5404675013203c8dce11e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for protoverta 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for protoverta-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page