Skip to content

Python

The platform is OpenAI-compatible, so use the official openai SDK and just change base_url. Claude / Gemini can use their official SDKs pointed at the platform too.

OpenAI SDK

bash
pip install openai
python
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-key",
    base_url="https://gateway.mindproxy.ai/v1",
)

resp = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)

Streaming

python
stream = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Write a short poem"}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)

Embeddings

python
emb = client.embeddings.create(
    model="text-embedding-3-small",
    input="some text",
)
print(len(emb.data[0].embedding))

Image generation

python
img = client.images.generate(
    model="gpt-image-1",
    prompt="a city at night",
    n=1,
    size="1024x1024",
)
print(img.data[0].url)

Claude (Anthropic SDK)

bash
pip install anthropic
python
from anthropic import Anthropic

client = Anthropic(
    api_key="sk-your-key",
    base_url="https://gateway.mindproxy.ai",  # SDK appends /v1/messages
)

msg = client.messages.create(
    model="claude-3-5-sonnet",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)

Passing extra headers

For dry-run or idempotency, add custom headers:

python
resp = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}],
    extra_headers={
        "Idempotency-Key": "my-unique-key-001",
        # "X-TT-Dry-Run": "true",  # estimate only, no model call, no charge
    },
)

Troubleshooting

  • Auth fails: check api_key and base_url (the OpenAI SDK base_url must include /v1).
  • 404: check whether the base_url ends with one too many / too few /v1.
  • Error shapes and status codes: Errors & rate limits.

Gateway: gateway.mindproxy.ai · Built with VitePress