Examples

Use the Anthropic Messages API

Point the Anthropic SDK at api.redgold.ai and authenticate with a bearer token instead of x-api-key.

Goal

Call a Redgold model through the Anthropic Messages API shape on the Redgold model API.

Prerequisites

  • An sk-rg- key in REDGOLD_API_KEY (see Create an API key).
  • pip install anthropic.
  • A /v1/messages-family model id from /v1/models (see Model API).

Steps

Two details differ from a direct Anthropic call. Set base_url to the host without a /v1 suffix — the SDK appends /v1/messages itself. And present the key on the Authorization: Bearer header, because the model API reads that header, not the x-api-key the SDK sends by default.

import os
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.redgold.ai",
    api_key="unused",  # the model API reads Authorization, not x-api-key
    default_headers={"Authorization": f"Bearer {os.environ['REDGOLD_API_KEY']}"},
)

with client.messages.stream(
    model="model-id-from-v1-models",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="")

Expected output

The assistant's reply streamed to stdout token by token.

When it breaks

  • 401 — the key reached the API only as x-api-key. Confirm the Authorization: Bearer header is set in default_headers as shown.
  • 404 on /v1/messagesbase_url includes a /v1 suffix. Drop it; the SDK adds the path.
  • 400 unknown model — the id is not a /v1/messages-family model for your account. Read one from /v1/models.

Source

Model API (Anthropic Messages).

Copyright © 2026