Build Guides
Migrate from the OpenAI SDK in one line
The small set of configuration changes that moves an existing OpenAI-compatible client to EasyAI.

What you will learn
- Keep the SDK and isolate provider settings in environment variables.
- Make the model name configurable so switching is reversible.
- Validate streaming, errors, usage, and latency in staging.
Before you start
- Basic HTTP and API knowledge
Leave with a concrete implementation checklist and a testable starting point.
Key takeaways
- Keep the SDK and isolate provider settings in environment variables.
- Make the model name configurable so switching is reversible.
- Validate streaming, errors, usage, and latency in staging.
Keep your client
EasyAI accepts the OpenAI-compatible request format, so most applications can keep their existing SDK. The migration usually consists of changing the base URL, supplying an EasyAI API key, and choosing a model enabled for the account.
Keeping the client is useful beyond convenience: your streaming, timeout, structured-output, and error-handling code can continue to be tested against the same interface.
Change configuration, not business logic
Put the base URL and key in server-side environment variables. Do not expose keys in browser bundles or commit them to source control. Then make the model name configurable so you can compare models without changing application code.
For video or image workflows, use the endpoint documented for the enabled model and treat generation as an asynchronous or longer-running operation where appropriate.
Verify before production
Start with the quickstart request, confirm the response shape, and record latency and usage in a staging environment. Check the live model page for endpoint support and current reference pricing before moving traffic.
A gateway migration should be reversible: keep the provider settings behind one configuration boundary so a rollback is a deployment variable change, not a code rewrite.
Decision guide
| Criterion | Option A | Option B |
|---|---|---|
| Best when | You need predictable behavior and easy auditing | You need adaptive optimization and have reliable telemetry |
| Main risk | May leave performance on the table | Can become difficult to explain or debug |
Implementation steps
- 1
Create an EasyAI API key in the console.
- 2
Set the OpenAI-compatible base URL on the server.
- 3
Change only the model setting and run the quickstart request.
- 4
Promote gradually and keep the old provider configuration available.
Copy-ready example
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.EASYAI_API_KEY,
baseURL: "https://easyairoute.com/v1",
});
const completion = await client.chat.completions.create({
model: process.env.EASYAI_MODEL ?? "deepseek-chat",
messages: [{ role: "user", content: "Hello" }],
});Frequently asked questions
Do I need a new SDK?
Usually no. EasyAI uses an OpenAI-compatible request format, so the existing official SDK is often sufficient.
Where should the API key live?
Only in server-side environment variables or a secret manager, never in browser code.
Sources
- OpenAI API referenceSource checked 2026-08-27