Examples

Call the model API from Python

Drive /v1/chat/completions with the OpenAI SDK pointed at api.redgold.ai.

Goal

Send a chat completion from Python using the OpenAI SDK against the Redgold model API.

Prerequisites

Steps

Point the OpenAI client at https://api.redgold.ai/v1 and pass the key as the API key. The OpenAI SDK sends it as a bearer token, which is what the model API reads.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.redgold.ai/v1",
    api_key=os.environ["REDGOLD_API_KEY"],
)

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

response = client.chat.completions.create(
    model="redgold-flint",
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)

Read the model id from client.models.list() rather than hard-coding one — the available set changes independently of client code. For token streaming, pass stream=True and consume the SDK iterator.

Expected output

The printed list of model ids your account can reach, then the assistant's reply text from response.choices[0].message.content.

When it breaks

  • 401 — bad or missing key. Confirm REDGOLD_API_KEY is exported in the shell that runs Python.
  • 400 with an unknown-model message — refresh the id from client.models.list().
  • 429 — a rate limit. See Retry model API calls under rate limits.

Source

Model API (OpenAI Chat Completions).

Copyright © 2026