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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a4bd38cbc69ae7037107c167a495835724abbbf69924838feef3f8e87e1a0ea
|
|
| MD5 |
bdca012ebaa2d1ca199253f3ee67b15a
|
|
| BLAKE2b-256 |
14fd0ec5da634d6dca50ca201b5c211a89f39ef1a87f66580b403853c6f9ae1b
|
Provenance
The following attestation bundles were made for gatectr_sdk-0.1.0.tar.gz:
Publisher:
publish.yml on GateCtr/sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gatectr_sdk-0.1.0.tar.gz -
Subject digest:
3a4bd38cbc69ae7037107c167a495835724abbbf69924838feef3f8e87e1a0ea - Sigstore transparency entry: 1178415864
- Sigstore integration time:
-
Permalink:
GateCtr/sdk-python@fb125a541101d2f3fedb5b5f897dddf90911e402 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/GateCtr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb125a541101d2f3fedb5b5f897dddf90911e402 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6367d7359724d9b644be4260430459efd7c12ad6696f258cfb91e0875ef7fbda
|
|
| MD5 |
78b2d0dffa7de3f37245ee8877093673
|
|
| BLAKE2b-256 |
93930a6f479ac24d3432deb407ed31f072b9bff34a3cfb1cbed0b0f670a3172b
|
Provenance
The following attestation bundles were made for gatectr_sdk-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on GateCtr/sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gatectr_sdk-0.1.0-py3-none-any.whl -
Subject digest:
6367d7359724d9b644be4260430459efd7c12ad6696f258cfb91e0875ef7fbda - Sigstore transparency entry: 1178415872
- Sigstore integration time:
-
Permalink:
GateCtr/sdk-python@fb125a541101d2f3fedb5b5f897dddf90911e402 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/GateCtr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb125a541101d2f3fedb5b5f897dddf90911e402 -
Trigger Event:
push
-
Statement type: