Most AI tools and SDKs were written against the OpenAI API. Many other providers accept the same request format, so the same code can talk to them. These providers are called OpenAI-compatible. Moving between them usually means changing two settings: the base URL and the API key.
What "OpenAI-compatible" means
A provider is OpenAI-compatible when it serves the same paths with the same JSON shapes. The most common ones are:
| Endpoint | Used for |
|---|---|
POST /v1/chat/completions | Chat and most tools. The most widely supported format. |
POST /v1/responses | OpenAI's newer interface, used by Codex CLI and the Agents SDK. |
GET /v1/models | Lists the model IDs your key can use. |
POST /v1/images/generations | Image generation. |
POST /v1/embeddings | Text embeddings. |
Compatibility covers the request and response format. Each provider still decides which models it offers, so the model value must be a model ID that the provider lists.
The two settings you change
- Base URL. The address that comes before
/chat/completions. For OpenAI it ishttps://api.openai.com/v1. For AIDiscount it ishttps://aidiscount.ai/v1. - API key. The provider's own key, sent as
Authorization: Bearer sk-.... A key from one provider does not work at another.
Keep the key in an environment variable instead of in code:
# macOS / Linux
export AIDISCOUNT_API_KEY="sk-..."
# Windows PowerShell
$env:AIDISCOUNT_API_KEY="sk-..."
curl
curl https://aidiscount.ai/v1/chat/completions \
-H "Authorization: Bearer $AIDISCOUNT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash",
"messages": [{"role": "user", "content": "Hello"}]
}'
Python (official OpenAI SDK)
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["AIDISCOUNT_API_KEY"],
base_url="https://aidiscount.ai/v1",
)
resp = client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
The SDK also reads OPENAI_BASE_URL and OPENAI_API_KEY from the environment. If you set both, you can switch providers without touching the code at all.
Node.js (official OpenAI SDK)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.AIDISCOUNT_API_KEY,
baseURL: "https://aidiscount.ai/v1",
});
const resp = await client.chat.completions.create({
model: "deepseek-v4.1-flash",
messages: [{ role: "user", content: "Hello" }],
});
console.log(resp.choices[0].message.content);
Streaming works the same way
Add stream=True (Python) or stream: true (Node.js). The provider sends server-sent events in the same format as OpenAI.
stream = client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[{"role": "user", "content": "Write a haiku"}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Find the model IDs you can use
curl https://aidiscount.ai/v1/models \
-H "Authorization: Bearer $AIDISCOUNT_API_KEY"
The model marketplace shows the same IDs with their current prices.
Common mistakes
- 404 Not Found. The base URL is missing
/v1, or the tool adds/v1itself and you added it again. Try the other form. - 401 Unauthorized. The key belongs to a different provider, has a typo, or was deleted.
- Model not found. The model name is one the provider does not offer. Copy the exact ID from
/v1/models.
More fixes are in How to fix common AI API errors.
What about the Anthropic format?
Some tools speak the Anthropic Messages API instead (POST /v1/messages with an x-api-key header). AIDiscount accepts that format too. For the Anthropic SDK, use the base URL https://aidiscount.ai without /v1, because the SDK adds /v1/messages itself. The API docs have full examples.
Create a free accountRead the API docs