TitanGPT Python SDK
The official sync and async Python SDK for the OpenAI-compatible TitanGPT API.
- Python 3.8+
- Synchronous and asynchronous clients
- Responses accessible as dictionaries or through attributes
- Typed API exceptions with request IDs and OpenAI-compatible error metadata
- Automatic retries for retryable idempotent requests
Installation
python -m pip install --upgrade titangpt
Set your API key in the environment:
export TITANGPT_API_KEY="YOUR_API_KEY"
PowerShell:
$env:TITANGPT_API_KEY = "YOUR_API_KEY"
You can also pass api_key directly to either client.
Quick start
Synchronous client
from titangpt import TitanGPT
with TitanGPT() as client:
response = client.chat.completions.create(
model="gpt-5.6-terra",
messages=[
{"role": "user", "content": "Write a haiku about Python."},
],
)
print(response.choices[0].message.content)
TitanResponse behaves like a normal dictionary, so the same value is also
available as response["choices"][0]["message"]["content"].
Asynchronous client
import asyncio
from titangpt import AsyncTitanGPT
async def main() -> None:
async with AsyncTitanGPT() as client:
response = await client.chat.completions.create(
model="gpt-5.6-terra",
messages=[{"role": "user", "content": "Explain async I/O briefly."}],
)
print(response.choices[0].message.content)
asyncio.run(main())
Configuration
from titangpt import TitanGPT
client = TitanGPT(
api_key="YOUR_API_KEY", # or TITANGPT_API_KEY
base_url="https://api.titangpt.xyz",
timeout=60,
max_retries=3,
user_id="12345",
)
max_retries applies to retryable GET, HEAD, and OPTIONS requests. The
client retries HTTP 429, 500, 502, 503, and 504 responses with bounded
exponential backoff.
Error handling
HTTP and transport failures are exposed as typed exceptions:
from titangpt import (
AuthenticationError,
ModelNotFoundError,
RateLimitError,
TitanGPT,
TitanGPTException,
)
try:
with TitanGPT() as client:
client.chat.completions.create(
model="unknown-model",
messages=[{"role": "user", "content": "Hello"}],
)
except ModelNotFoundError as exc:
print(exc.message)
print(exc.code) # model_not_found
print(exc.request_id) # include this when contacting support
except (AuthenticationError, RateLimitError) as exc:
print(exc.status_code, exc.message)
except TitanGPTException as exc:
print(f"TitanGPT request failed: {exc}")
API exceptions expose these diagnostic attributes:
| Attribute | Description |
|---|---|
message |
Human-readable API error message |
status_code |
HTTP status code, when available |
error_type |
OpenAI-compatible error type |
param |
Request parameter associated with the error |
code |
Stable API error code, such as model_not_found |
request_id |
Server request ID for diagnostics and support |
response_body |
Parsed response body or raw response text |
Available exception classes include AuthenticationError,
AuthorizationError, ValidationError, RateLimitError,
ModelNotFoundError, NotFoundError, TimeoutError, ConnectionError,
DataError, and APIError. All inherit from TitanGPTException.
API areas
The SDK currently provides:
client.chat.completionsclient.models.list()client.filesclient.threadsclient.usageclient.audio.transcriptionsclient.music.youtubeclient.music.yandex
The async client exposes the same areas with awaitable methods.
Development
python -m pip install -e ".[dev]"
python -m unittest discover -s tests -v
python -m build
python -m twine check --strict dist/*
See the changelog for release notes.
Links
License
MIT
Metadata
Release files for titangpt 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| titangpt-0.2.4.tar.gz | 16.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| titangpt-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.5 kB
Release files / titangpt-0.2.4.tar.gz
| Download URL | titangpt-0.2.4.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09fb943cd9d5c4ca9452cc3ee20c09e9e4c7ab1c3843b0cc81c2a084d4cb43ef
|
|
BLAKE2b-256 checksum How to use checksums |
34ff319862da6f0221c4b1a0bebcefa6ef10fcb00228cfc4397055693cb69f5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / titangpt-0.2.4-py3-none-any.whl
| Download URL | titangpt-0.2.4-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fafab360f8b1b7bcfec90561680afdad131479f82fe6d961d178cde64d575e14
|
|
BLAKE2b-256 checksum How to use checksums |
44c1f698f5c7f996f5566415e2bb6dc4ad0a61b9a5071edf801fac2278a7558e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|