Skip to main content

Drop-in OpenAI-compatible Python SDK for the Pump LLM gateway

Project description

pump Python SDK

A drop-in replacement for the official OpenAI Python SDK for pump — a multi-tenant LLM gateway that exposes an OpenAI-compatible API.

Keep your existing OpenAI request code exactly as-is. The only things that change are the import, the base_url, and using your pump key (pk-...) as the API key.

Installation

pip install pumpsdk

The distribution is published as pumpsdk; the import package is pump.

Quickstart — OpenAI drop-in

# before:
# from openai import OpenAI
# client = OpenAI()

from pump.openai import OpenAI

client = OpenAI(
    base_url="https://api.pump.co/ai/v1",
    api_key="pk-...",  # your pump key (or set PUMP_API_KEY)
)

resp = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello!"}],
)

print(resp.choices[0].message.content)

That's the whole migration. Every standard parameter (temperature, tools, tool_choice, response_format, seed, stream, ...) is forwarded to the gateway unchanged.

Pump is the same client under a more obvious name — from pump import Pump and from pump.openai import OpenAI are interchangeable.

API key

Pass api_key="pk-..." explicitly, or omit it and the SDK reads PUMP_API_KEY from the environment:

export PUMP_API_KEY="pk-..."
from pump.openai import OpenAI

client = OpenAI()  # base_url defaults to https://api.pump.co/ai/v1

Responses & embeddings

client.responses.create(model="gpt-4o-mini", input="Write a haiku about pumps.")

client.embeddings.create(model="text-embedding-3-small", input="hello world")

Streaming

The streamed object is iterable directly — no context manager required:

stream = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Count to 5"}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta
    if getattr(delta, "content", None):
        print(delta.content, end="", flush=True)

You can also use it as a context manager to guarantee the connection closes:

with client.chat.completions.create(..., stream=True) as stream:
    for chunk in stream:
        ...

Async

import asyncio
from pump.openai import AsyncOpenAI

async def main():
    client = AsyncOpenAI(api_key="pk-...")

    resp = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(resp.choices[0].message.content)

    # async streaming
    stream = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Count to 5"}],
        stream=True,
    )
    async for chunk in stream:
        ...

    await client.aclose()

asyncio.run(main())

Attaching metadata & tags (pump extension)

pump lets you attach observability metadata and tags to any request. These are not part of the OpenAI request body — sending custom fields there would be rejected by the upstream provider. Instead, pass them as explicit kwargs and the SDK sends them as gateway headers (x-pump-metadata, x-pump-tags), which the gateway reads and strips before forwarding the request upstream.

resp = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello!"}],
    metadata={"user_id": "u_123", "feature": "support-bot"},
    tags=["prod", "support"],
)

You can also pass arbitrary headers via extra_headers:

client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[...],
    extra_headers={"x-pump-trace-id": "abc123"},
)

Note: OpenAI's own body-level metadata field (for stored completions) is a different thing. If you need it, pass it through extra_body={"metadata": {...}}.

Response objects

Responses support both attribute access and dict access, and expose .model_dump() to get a plain dict:

resp = client.chat.completions.create(...)

resp.choices[0].message.content        # attribute access
resp["choices"][0]["message"]["content"]  # dict access
resp.model_dump()                       # plain dict

Error handling

The SDK raises a single error type, pump.PumpError. For HTTP failures it carries the status_code (and response) so you can branch on it:

from pump import PumpError

try:
    client.chat.completions.create(...)
except PumpError as e:
    if e.status_code == 429:
        ...  # rate limited
    elif e.status_code == 401:
        ...  # bad API key
    else:
        raise

Roadmap: more providers

The SDK is built on a shared transport so additional provider shims can be added without changing existing code. An Anthropic-compatible shim (from pump.anthropic import Anthropic) is reserved as an extension point and will land once the gateway exposes an Anthropic-compatible endpoint.

Development

pip install -e ".[dev]"
pytest

Tests use httpx.MockTransport and never call the real API.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pumpsdk-0.2.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pumpsdk-0.2.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file pumpsdk-0.2.0.tar.gz.

File metadata

  • Download URL: pumpsdk-0.2.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pumpsdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 03fb2a49ea2023f7d3cc85a78554951a923b684789cd07420bc3dbd87b955a06
MD5 9bf394c04980f91d17b6c36ce995f3b5
BLAKE2b-256 33d930adab716846aea3959874423674845fd170a6df1c3f3ad7d42af133f7b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pumpsdk-0.2.0.tar.gz:

Publisher: publish.yml on pumpcard/pump-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pumpsdk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pumpsdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pumpsdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3b414b74c7af5ee292495047fc4293cd17471795ad0d5766764bc88a11313c1
MD5 6a9c8c93a2fd6f8186b3d91742c095a2
BLAKE2b-256 b0f0b1ad1a36f37995066b0e67a101c241760059e8f60ab69aee7a9d5b10ef59

See more details on using hashes here.

Provenance

The following attestation bundles were made for pumpsdk-0.2.0-py3-none-any.whl:

Publisher: publish.yml on pumpcard/pump-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page