Skip to main content

respan-gateway for Python

The respan-gateway LLM gateway as a Python package: use it in-process with the official OpenAI and Anthropic SDKs (no socket, no server), run it as a local server, or use the same command line as the Rust binary. The gateway is the Rust one, compiled into a native extension (abi3, Python 3.10+).

Status: pre-alpha, like the gateway itself.

Install

pip install respan-gateway            # add `openai` and/or `anthropic` for gw.openai() / gw.anthropic()

Use the SDKs in-process

import respan_gateway as rg

with rg.Gateway() as gw:             # from OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY, ...
    client = gw.openai()             # an openai.OpenAI that talks to gw directly

    # A Claude model through the OpenAI SDK is translated to Anthropic.
    reply = client.chat.completions.create(
        model="claude-haiku-5-5", messages=[{"role": "user", "content": "hi"}]
    )

gw.anthropic() is the same for anthropic.Anthropic; gw.openai_async() and gw.anthropic_async() give the async clients. Leaving the with (or async with) block stops the servers the gateway started and closes the clients it handed out. For any other httpx-based client, gw.transport() and gw.async_transport() are httpx transports: httpx.Client(transport=gw.transport()). Raw requests: gw.request("POST", "/v1/chat/completions", json=...) returns an httpx.Response; gw.stream(...) yields the body chunk by chunk as it arrives. arequest and astream are the asyncio versions.

Every kind

Each kind is an OpenAI endpoint the gateway serves when a provider speaks its format (openai-images, openai-transcriptions, openai-speech, openai-embeddings, openai-videos; see gateway.example.toml), and works through the same client:

client.images.generate(model="gpt-image-1", prompt="a red fox").data[0].b64_json

with open("talk.wav", "rb") as f:                      # a multipart upload
    client.audio.transcriptions.create(model="whisper-1", file=f).text

client.audio.speech.create(model="tts-1", voice="alloy", input="hi").read()   # audio bytes

client.embeddings.create(model="text-embedding-3-small", input="hi").data[0].embedding
# (the SDK asks for base64 and decodes it; the gateway passes it through)

job = client.videos.create(model="veo-3.0-generate-001", prompt="waves")  # Veo; then poll:
job = client.videos.retrieve(job.id)                             # queued -> completed
client.videos.download_content(job.id).read()                    # mp4 bytes

A model's kind is read from its name and the providers' formats: gw.models() lists the merged models of every provider as /v1/models does, each with its kind (gw.models(kind="image") filters).

Errors

HTTP error statuses are responses (and the SDKs raise their own exceptions for them), never exceptions of this package. A failure to carry out a request or start a server is a GatewayError. A timeout is httpx's httpx.ReadTimeout, which an SDK raises as its own timeout error. An invalid configuration is a ConfigError (a ValueError).

What the gateway knows

gw.models()                # [{"id": "gpt-image-1", "owned_by": "openai", "kind": "image"}, ...]
gw.providers()             # each provider with its formats and request counts
gw.requests(limit=20)      # the request log, newest first; filters such as client="ci" (a client key's name)

amodels(), aproviders() and arequests() are the asyncio versions. providers() and requests() read the web UI's admin API in-process, so ui = false turns them off (the log is in memory, always on with the UI). A gateway in your process prints nothing per request: log defaults to off here (the binary's is text). Set log = 'text' or log = 'json' in the config for stderr lines, serve_forever() included.

Serve

with gw.serve(port=0) as server:     # a real socket, in the background
    print(server.url)                # http://127.0.0.1:54321

async with gw.aserve() as server:    # the same for asyncio
    ...

gw.serve_forever(port=8080)          # blocks; Ctrl-C stops it (serve() picks a free port by default)

The server is the binary's (server.url + "/ui/" is the web UI; wheels from PyPI embed it, a build from the sdist or a plain checkout shows a placeholder page unless apps/ui is built first). Without client_keys in the config, anyone who reaches it spends your provider keys: keep it on a local address. Gateway.openai()'s api_key is one of those client keys when the config sets them; otherwise a placeholder, forwarded only to a provider with no key of its own.

Realtime

WebSocket sessions (OpenAI Realtime, Gemini Live, translated between each other) need a socket: use serve() and connect any WebSocket client, with http replaced by ws:

import websockets

with gw.serve() as server:
    async with websockets.connect(server.url.replace("http", "ws") + "/v1/realtime?model=gpt-realtime") as ws:
        ...

Command line

respan-gateway                                # also: init, check, proxy --anthropic|--openai, --help
python -m respan_gateway proxy --openai

Configuration

Gateway(config=...) takes a dict (typed as rg.GatewayConfig for editor completion) or a TOML string in the format of gateway.example.toml; Gateway.from_file(path) reads a file. With no config, Gateway() starts as the binary does with no arguments: from ./gateway.toml if it exists, else from the environment: every vendor whose key is set (OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY, GROQ_API_KEY, ...) becomes a provider, models route by name (claude-* to Anthropic, gemini-* to Gemini, or explicitly groq/openai/gpt-oss-20b), and RESPAN_<VENDOR>_BASE_URL points one elsewhere.

Development

cd python
uv venv && uv pip install maturin pytest httpx openai anthropic mypy
.venv/bin/maturin develop        # builds the extension into .venv
.venv/bin/pytest                 # tests run against a fake provider, offline
.venv/bin/mypy --strict python/respan_gateway

The extension is the respan-gateway-python crate (src/), a workspace member that depends on the respan-gateway library in apps/gateway. The extension-module feature is enabled by maturin only, so cargo test and cargo clippy of the workspace link normally. One tokio runtime, started on first use, serves every gateway, server and the command line; every call that waits releases the GIL. Async requests use a native callback API (send_async, next_chunk_async) rather than executor threads: a waiting request holds no thread, so many open streams cannot starve anything, and cancelling the awaiting task drops the in-flight router future, which cancels the provider call. Sync calls block with the GIL released and wake every 100 ms to deliver Ctrl-C. httpx's read timeout bounds the wait for the response head and each body chunk (connect, write and pool timeouts have nothing to bound in-process). A server from serve() keeps running when its handle is dropped, until stop() or the process exits.

Metadata

Release files for respan-gateway 0.1.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 respan-gateway 0.1.0
File Size Uploaded Provenance
respan_gateway-0.1.0.tar.gz 707.2 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for respan-gateway 0.1.0
File
respan_gateway-0.1.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
respan_gateway-0.1.0-cp310-abi3-manylinux_2_39_x86_64.whl CPython 3.10 abi3 Linux glibc 2.39+ x86-64 Details
respan_gateway-0.1.0-cp310-abi3-manylinux_2_39_aarch64.whl CPython 3.10 abi3 Linux glibc 2.39+ ARM64 Details
respan_gateway-0.1.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
respan_gateway-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 46.3 MB

Release files / respan_gateway-0.1.0.tar.gz

Download URL respan_gateway-0.1.0.tar.gz
Size 707.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b808d750b9b0d4d507afd69ec0de0c413cb20361323915867993df41f2124256
BLAKE2b-256 checksum
How to use checksums
cd646c1591ce2216d32043799d6398745e1fd028a9bc9f989cc5ffe1744ee86a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 19, 2026.

Transparency log

Release files / respan_gateway-0.1.0-cp310-abi3-win_amd64.whl

Download URL respan_gateway-0.1.0-cp310-abi3-win_amd64.whl
Size 9.0 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
9ba860e44dcfe2e22d18c9b8562a913a6896e1114e284a79cf43d2142450108f
BLAKE2b-256 checksum
How to use checksums
da9a69586d3dea25f85ce4042e2d68709ffa91f0d979585e7c561bc2db908664
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 19, 2026.

Transparency log

Release files / respan_gateway-0.1.0-cp310-abi3-manylinux_2_39_x86_64.whl

Download URL respan_gateway-0.1.0-cp310-abi3-manylinux_2_39_x86_64.whl
Size 9.5 MB
Tags CPython 3.10 Linux glibc 2.39+ x86-64 abi3
SHA-256 checksum
How to use checksums
2dab89104ca480afc56f63784e80fc9ddcda9c7794569803444bcb58bb0f6ad9
BLAKE2b-256 checksum
How to use checksums
6371387dbeecb4d306253746695080e9301471a4a87785ba3a007d75279a959b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 19, 2026.

Transparency log

Release files / respan_gateway-0.1.0-cp310-abi3-manylinux_2_39_aarch64.whl

Download URL respan_gateway-0.1.0-cp310-abi3-manylinux_2_39_aarch64.whl
Size 9.3 MB
Tags CPython 3.10 Linux glibc 2.39+ ARM64 abi3
SHA-256 checksum
How to use checksums
45ae91940ae13356f3f47b6dcd0a9b56585c64159d1515f82802b7d137d4c7c3
BLAKE2b-256 checksum
How to use checksums
3d9c877a740b35b3a00a3a74f35900e27c3f34c05d68cc392becad513af59873
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 19, 2026.

Transparency log

Release files / respan_gateway-0.1.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL respan_gateway-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Size 8.8 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
fd401c50f705eed01c30b43ef9c307d4ad39f6b9b046a9a4a3dc422ec02e992c
BLAKE2b-256 checksum
How to use checksums
01f69746002646dc39bf4ebf5454c74ec86876f9b49d687fc94694e9deb16dff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 19, 2026.

Transparency log

Release files / respan_gateway-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL respan_gateway-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 9.1 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
1a0a20815bba2c26c30957a4bb56fa53e0d145dfc28c87e051b8b6e6be6d1bf8
BLAKE2b-256 checksum
How to use checksums
9fbe80184642c890afec37acbbd55e2e1795086e7d98164150aa950a7e97a519
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 19, 2026.

Transparency log

Security for respan-gateway 0.1.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

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for respan_gateway-0.1.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 Oct 19, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

6 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