ultrarouter docs
Migrate

From OpenAI direct

Field-by-field mapping from the OpenAI API to ultrarouter.

The official openai client runs unmodified against ultrarouter — change the base URL and key only.

  import OpenAI from "openai";
  const client = new OpenAI({
-   apiKey: process.env.OPENAI_API_KEY,
+   baseURL: "http://localhost:8080/v1",   // or your gateway URL
+   apiKey:  process.env.UR_API_KEY,        // ur_sk_live_… / ur_sk_test_…
  });

chat.completions.create, embeddings.create, and models.list all work with the same request/response shapes (streaming included).

Field-by-field mapping

OpenAIultrarouterNotes
model: "gpt-4o"model: "openai/gpt-5.2"Prefix the model with its provider.
messages, tools, response_format, streamsameUnchanged request fields.
Authorization: Bearer sk-…Authorization: Bearer ur_sk_…ultrarouter key.
(n/a)model: "anthropic/…", "google/…", …Reach 13 other providers with the same client.
(n/a)call_type, router, compression, models, providerOptional ultrarouter extensions.
usageusage + ur blockExtra ur metadata (id, provider served, cost, routing).

Notable differences

  • Model ids are provider-prefixed (openai/gpt-5-mini, not gpt-4o-mini) so you can mix providers with one client.
  • Extensions are additive — call_type, router, compression, models, provider, and the ur request options are ignored by a plain OpenAI client but understood by the gateway.
  • Everything is achievable with raw REST too — see the API reference.