← ALL DEVELOPER GUIDES
PYTHON SETUP

Use the OpenAI Python SDK with a custom API base URL

Use the OpenAI Python client with your CheapClankers key and API base URL. This example calls chat completions; first select a model whose current catalogue entry supports chat.

Updated

1. Create a key and select a model

Create and verify your developer account, then create an API key in the dashboard. Store it in your shell or server environment. Never place a private key in a notebook shared publicly, frontend code, or a checked-in file.

Check the key's model list and select an enabled model that supports chat completions. Catalogue availability and model IDs can change; use a current ID available to your key.

Shell
export CLANKER_API_KEY="your_key_here"
export CLANKER_MODEL="your_enabled_chat_model_id"

2. Install the SDK

Use a Python version supported by the current SDK and install the package in your project environment, preferably a virtual environment. The environment examples use Bash or zsh. In PowerShell use $env:CLANKER_API_KEY = "your_key_here" and $env:CLANKER_MODEL = "your_enabled_chat_model_id".

Shell
python -m pip install openai

3. List available models and make a request

Save this as setup.py and run python setup.py in the same shell where you set your variables. Pass the versioned API root as base_url. The model list response is scoped to your key; check the catalogue separately for current status and chat support.

After replacing the placeholder model, expect a printed model ID list and a short greeting if the model is available and your wallet has sufficient credit. Confirm the request and charge in dashboard usage history.

Python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["CLANKER_API_KEY"],
    base_url="https://api.cheapclankers.com/v1",
)

models = client.models.list()
print([model.id for model in models.data])

response = client.chat.completions.create(
    model=os.environ["CLANKER_MODEL"],
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
    max_tokens=128,
)
print(response.choices[0].message.content)
  • Use a model ID returned for your key.
  • Confirm chat is one of the model's supported protocols.
  • Input and output usage consume prepaid credit at separately published rates.

Troubleshooting

A 401 points to a missing, invalid or revoked key; a 403 can mean the key restricts model access. A 404 can mean the model is unavailable or does not support chat. A KeyError for CLANKER_API_KEY or CLANKER_MODEL means the variable is missing from the Python process environment. Check the wallet if the API reports insufficient credit.

For a timeout or upstream error, keep the request ID and check usage history before retrying. An interrupted response does not by itself establish that no usage was recorded.

Official tool documentation

These examples describe the endpoint configuration. Review current SDK or tool requirements before installing; live inference and tool support depend on the selected model.

Next steps

Live model catalogue · Published rates and credit packs · API documentation

More tutorials: Use an OpenAI-compatible API in a Next.js Route Handler · Add CheapClankers as a LibreChat custom endpoint · Use the OpenAI Node SDK with a custom API base URL · Configure Claude Code to use the CheapClankers API · Codex CLI setup

New to the service? Create a developer account and review the current model access and rates before adding credit.