OpenAI Migration
Move a supported OpenAI client to Elektric.
If you already use the OpenAI SDK, keep the client and change the API key, base URL, and model.
#What changes
Use the same chat.completions.create request shape where supported. The API key authenticates with Elektric, the base URL becomes https://elektric.ai/v1, and the model selects Grid or Wire.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.ELEKTRIC_API_KEY,
baseURL: "https://elektric.ai/v1",
});
const response = await client.chat.completions.create({
model: "elektric-grid",
messages: [{ role: "user", content: "Hello" }],
});#Use Grid
Set model: "elektric-grid" and Elektric selects an eligible model for the request.
#Use Wire
Wire sends the request to the exact public model ID you provide instead of routing it through Grid. Use model: "<public-model-id>" and discover current IDs with the Models page or authenticated GET /v1/models.
#What stays the same
chat.completions.create(...)and the standard message roles remain available.- Chat streaming is supported through the OpenAI-compatible SSE response.
- Function tools are supported for non-streaming tool turns.
- Structured output is supported with
response_formatusingtype: "json_schema"on non-streaming requests.
#Compatibility limits
Elektric supports a focused OpenAI-compatible surface, not every OpenAI endpoint or option.
- The supported endpoint is
POST /v1/chat/completions; use Elektric’s native APIs for other resources. - Unknown request fields are rejected.
nsupports only1; use eithermax_tokensormax_completion_tokens, not both. - Streaming function tools and streaming structured output are not supported. Tool turns must be non-streaming, and structured output must use the supported JSON-schema form.
- Wire capability and parameter support varies by selected model. Images, documents, web search, reasoning, tools, and output limits are model-specific; check
GET /v1/models.
#Errors and debugging
Authentication failures return 401 authentication_error. Invalid requests and unsupported fields return 400 invalid_request_error; an unavailable named model returns 400 model_selection_not_supported. Responses include a Request ID; inspect it with Usage logs when debugging. See Errors and limits →
#Next steps
Next: learn how Grid routes, use Wire for exact model selection, or browse available models.
