Using the OpenAI-compatible /chat/completions endpoint
Learn how to use the OpenAI-compatible /chat/completions endpoint with our API aggregator. Change one base URL and reuse your existing OpenAI or LangChain code to access multiple models with a single key, paying USDC on Base with no KYC.
Why an OpenAI-compatible endpoint?
The OpenAI chat completions API has become a de facto standard for interacting with large language models. Many SDKs, frameworks, and tools expect this format. By providing an OpenAI-compatible /chat/completions endpoint, our aggregator lets you use your existing code with minimal changes. You can switch between models from different providers (Claude, GPT, DeepSeek, Qwen, GLM, Kimi) using the same request structure.
What you need
- An API key from our aggregator (top up with USDC on Base, no KYC required).
- The base URL for our API endpoint. You can find it in your dashboard after signing up.
- Any HTTP client or SDK that supports the OpenAI chat completions format.
Making a request
The endpoint follows the OpenAI specification. You send a POST request with a JSON body containing at least model and messages. For example:
curl https://api.aggregator.example/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-sonnet",
"messages": [{"role": "user", "content": "Hello!"}]
}'
The response mirrors the OpenAI format, with choices containing the model's reply. This consistency means you can swap models by changing the model parameter without rewriting your application logic.
Using the OpenAI SDK
If you're using the official OpenAI Python or Node.js SDK, you only need to change the base_url (or baseURL in Node) and use your aggregator API key. For example, in Python:
from openai import OpenAI
client = OpenAI(
base_url="https://api.aggregator.example/v1",
api_key="YOUR_API_KEY"
)
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
This pattern works with any model we support. The SDK doesn't need to know which provider is behind the scenes.
Using LangChain
LangChain's ChatOpenAI class also accepts a custom base_url. Point it to our endpoint and provide your aggregator key:
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://api.aggregator.example/v1",
api_key="YOUR_API_KEY",
model="deepseek-chat"
)
response = llm.invoke("Hello!")
print(response.content)
Because LangChain relies on the OpenAI-compatible interface, all its features (streaming, function calling, etc.) work as long as the underlying model supports them.
Supported parameters
Our endpoint accepts the standard OpenAI parameters, including:
model(required)messages(required)temperature,topp,maxtokensstreamstop,presencepenalty,frequencypenaltytoolsandtool_choice(for models that support function calling)
Parameter support may vary by model. Refer to the model's documentation for details.
Pricing and billing
You pay the official price multiplied by 1.3 for each request, billed in USDC on Base. If you contribute keys, you earn credits at official price ×1.1 (or ×1.2 for premium keys) in USDC. There are no hidden fees, and you only pay for what you use.
Error handling
Errors follow the OpenAI error format, with a JSON object containing error with message, type, and code. Common errors include invalid API key, insufficient balance, or unsupported model. Handle them as you would with the OpenAI API.
Next steps
- Explore the models available in your dashboard.
- Try streaming responses for real-time applications.
- Use function calling to build agents.
- Monitor your usage and top up with USDC when needed.