integration · 2026-09-28

Connect the OpenAI Python SDK to RelayAI

Set your API key and base URL, inspect the models available to that key, and then make a small compatibility request.

RelayAI · 中文

Check account access first

Complete the applicable RelayAI account verification and create an API key in the console. Access to domestic and overseas models has different requirements. Query the model list with the same key you will use in production; a public example does not prove your account is authorized for a model.

Configure the SDK

Install the OpenAI Python SDK and point it to https://api.relayai.com.cn/v1. Read the key from an environment variable rather than committing it to source control. This first request prints the models visible to your key.

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["RELAY_API_KEY"],
    base_url="https://api.relayai.com.cn/v1",
)
print([model.id for model in client.models.list().data])

Validate the connection

Start with a small request using a returned model ID. For a 401 response, check the Bearer key; for 403, check model access. Model IDs, pricing and availability can change. Use the current console and API documentation for the final values.

Sources

Read API docs

Related articles

Streaming, timeouts and retries in an API client