Python OpenAI Official SDK (AutoGPT, LangChain, etc.)
Option 1: Configure OpenAI directly
import openai
# Set API base URL and key
openai.api_base = "https://4zapi.com/v1"
openai.api_key = "sk-xxxxxxxxx"
Option 2: Environment variables
If Option 1 does not work, try this.
Set these environment variables:
OPENAI_API_BASE=https://4zapi.com/v1
OPENAI_API_KEY=sk-xxxxx
Note: If changes do not take effect, restart the system.
Option 3: OpenAI client
from openai import OpenAI
# Initialize client
client = OpenAI(
base_url="https://4zapi.com/v1",
api_key='YOUR_API_KEY',
timeout=120
)
# Create chat completion
response = client.chat.completions.create(
model="gpt-6-luna",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)
print(response)
# responses format
response = client.responses.create(
model="gpt-5.6-sol",
input="Write a one-sentence bedtime story about a unicorn."
)
print(response.output_text)