Skip to content

Python SDK Guide

Python SDK Guide

Installation

Terminal window
pip install openai

Setup

from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://cryptgpt.co/v1"
)

Basic Usage

response = client.chat.completions.create(
model="gemma-4-26b",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)

Streaming

stream = client.chat.completions.create(
model="gemma-4-26b",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")

Error Handling

from openai import AuthenticationError, RateLimitError
try:
response = client.chat.completions.create(...)
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Rate limited — implement backoff")