Skip to content
Main Site News Console

Compatibility Mode Invocation (SDK Integration)

4ALL API fully implements the OpenAI interface protocol, so the official SDK and all OpenAI-compatible clients can be used directly, with no code changes required—even when calling non-OpenAI models such as Claude and Gemini, requests and responses are unified into the OpenAI format.

Python

from openai import OpenAI
client = OpenAI(
base_url="https://api.4allapi.com/v1",
api_key="sk-你的令牌",
)
resp = client.chat.completions.create(
model="claude-sonnet-5", # 换成任意在售模型即可
messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content)

Node.js

import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.4allapi.com/v1',
apiKey: 'sk-你的令牌',
});
const resp = await client.chat.completions.create({
model: 'gpt-5.5',
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(resp.choices[0].message.content);

Environment Variable Method

Most tools support environment variables, so there is no need to modify the code:

Terminal window
export OPENAI_BASE_URL="https://api.4allapi.com/v1"
export OPENAI_API_KEY="sk-你的令牌"

Notes