Python Examples

Use the official OpenAI Python SDK by pointing base_url to gpt88.cc. Includes sync, async, streaming, function calling, and retry patterns.

Install and configure

Use the official OpenAI SDK directly. No private gpt88 package is required. Version 1.40 or higher is recommended for complete support of streaming, tools, and response formatting.

Replace sk-xxx with the key created in the Agent API Keys.

bash
pip install openai>=1.40.0

# export the API key instead of hardcoding it
export GPT88_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx

Basic call

basic.pypython
from openai import OpenAI

client = OpenAI(
    base_url="https://api.gpt88.cc",
    api_key="YOUR_GPT88_API_KEY",
)

resp = client.chat.completions.create(
    model="claude-opus-4-8",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Introduce gpt88.cc in under 30 words"},
    ],
    temperature=0.7,
    max_tokens=1024,
)

print(resp.choices[0].message.content)
print("usage:", resp.usage.total_tokens, "tokens")

Streaming

stream.pypython
stream = client.chat.completions.create(
    model="claude-opus-4-8",
    stream=True,
    messages=[{"role": "user", "content": "Tell a short joke about API gateways"}],
)

for chunk in stream:
    delta = chunk.choices[0].delta.content or ""
    print(delta, end="", flush=True)
print()

Function calling

tools.pypython
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

resp = client.chat.completions.create(
    model="claude-opus-4-8",
    messages=[{"role": "user", "content": "What's the weather in Shanghai?"}],
    tools=tools,
    tool_choice="auto",
)

tc = resp.choices[0].message.tool_calls
if tc:
    print("model wants to call:", tc[0].function.name, tc[0].function.arguments)

When the model returns tool_calls, your application executes the tool and sends the tool result back as a role: "tool" message in the next request.

Errors and retries

retry.pypython
import time
from openai import OpenAI, RateLimitError, APIStatusError

client = OpenAI(base_url="https://api.gpt88.cc")

def call_with_retry(messages, model="claude-opus-4-8", max_retries=3):
    for attempt in range(max_retries):
        try:
            return client.chat.completions.create(
                model=model,
                messages=messages,
            )
        except RateLimitError:
            time.sleep(2 ** attempt)
        except APIStatusError as e:
            if 500 <= e.status_code < 600:
                time.sleep(2 ** attempt)
            else:
                raise
    raise RuntimeError("max retries exceeded")

See Error Codes for full status semantics.

Async usage

For FastAPI, asyncio, or higher-concurrency services, use AsyncOpenAI directly.

async.pypython
import asyncio
from openai import AsyncOpenAI

client = AsyncOpenAI(base_url="https://api.gpt88.cc")

async def main():
    resp = await client.chat.completions.create(
        model="claude-opus-4-8",
        messages=[{"role": "user", "content": "hi"}],
    )
    print(resp.choices[0].message.content)

asyncio.run(main())