Skip to main content

Python SDK for GateCtr — One gateway. Every LLM.

Project description

gatectr-sdk

The official Python SDK for GateCtr — the intelligent LLM gateway.

One endpoint swap. Full control. -40% tokens.

Installation

pip install gatectr-sdk

Requires Python 3.9+.

Quickstart

Async (recommended)

import asyncio
from gatectr import GateCtr

async def main():
    client = GateCtr(api_key="gct_your_api_key")

    # Text completion
    response = await client.complete(
        model="gpt-4o",
        messages=[{"role": "user", "content": "Hello, world!"}],
    )
    print(response.choices[0].text)
    print(f"Tokens saved: {response.gatectr.tokens_saved}")

    # Chat completion
    chat = await client.chat(
        model="gpt-4o",
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "What is GateCtr?"},
        ],
    )
    print(chat.choices[0].message.content)

    # Streaming
    async for chunk in client.stream(
        model="gpt-4o",
        messages=[{"role": "user", "content": "Tell me a story."}],
    ):
        if chunk.delta:
            print(chunk.delta, end="", flush=True)

    await client.aclose()

asyncio.run(main())

Async context manager

from gatectr import GateCtr

async with GateCtr(api_key="gct_your_api_key") as client:
    response = await client.complete(
        model="gpt-4o",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(response.choices[0].text)

Sync wrapper

from gatectr import SyncGateCtr

client = SyncGateCtr(api_key="gct_your_api_key")

response = client.complete(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].text)

Environment variable

Set GATECTR_API_KEY and omit the api_key argument:

export GATECTR_API_KEY=gct_your_api_key
from gatectr import GateCtr

client = GateCtr()  # reads from GATECTR_API_KEY

Configuration

client = GateCtr(
    api_key="gct_your_api_key",
    base_url="https://api.gatectr.com/v1",  # default
    timeout=30.0,                            # seconds, default 30
    max_retries=3,                           # default 3
    optimize=True,                           # Context Optimizer, default True
    route=False,                             # Model Router, default False
)

Error handling

from gatectr import GateCtr, GateCtrApiError, GateCtrTimeoutError

async with GateCtr() as client:
    try:
        response = await client.complete(model="gpt-4o", messages=[...])
    except GateCtrApiError as e:
        print(f"API error {e.status}: {e.code}")
    except GateCtrTimeoutError as e:
        print(f"Timed out: {e}")

License

MIT — see LICENSE.

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

gatectr_sdk-0.1.0.tar.gz (42.8 kB view details)

Uploaded Source

Built Distribution

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

gatectr_sdk-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file gatectr_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: gatectr_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 42.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for gatectr_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3a4bd38cbc69ae7037107c167a495835724abbbf69924838feef3f8e87e1a0ea
MD5 bdca012ebaa2d1ca199253f3ee67b15a
BLAKE2b-256 14fd0ec5da634d6dca50ca201b5c211a89f39ef1a87f66580b403853c6f9ae1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gatectr_sdk-0.1.0.tar.gz:

Publisher: publish.yml on GateCtr/sdk-python

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

File details

Details for the file gatectr_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gatectr_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for gatectr_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6367d7359724d9b644be4260430459efd7c12ad6696f258cfb91e0875ef7fbda
MD5 78b2d0dffa7de3f37245ee8877093673
BLAKE2b-256 93930a6f479ac24d3432deb407ed31f072b9bff34a3cfb1cbed0b0f670a3172b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gatectr_sdk-0.1.0-py3-none-any.whl:

Publisher: publish.yml on GateCtr/sdk-python

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