Call Nexus from the OpenAI SDK
You’ll get: your own code calling Nexus with the official OpenAI SDK. Change one address and one key; everything else stays the same.
You need:
- A Nexus API key. Make one in Connections.
- The address of the machine. On the machine itself it’s
http://127.0.0.1:3939/v1. Other addresses are on Connections → Gateway access.
Python
Section titled “Python”from openai import OpenAI
client = OpenAI( base_url="http://127.0.0.1:3939/v1", api_key="msty_nxs_...", # your Nexus key, not an OpenAI key)
reply = client.chat.completions.create( model="mlx/Jundot/gemma-4-26B-A4B-it-oQ6e-mtp", messages=[{"role": "user", "content": "Say hello in five words."}],)print(reply.choices[0].message.content)JavaScript
Section titled “JavaScript”import OpenAI from "openai";
const client = new OpenAI({ baseURL: "http://127.0.0.1:3939/v1", apiKey: process.env.NEXUS_API_KEY,});
const stream = await client.chat.completions.create({ model: "@route/everyday", messages: [{ role: "user", content: "Summarize this in one line: ..." }], stream: true,});for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? "");}What to put in model
Section titled “What to put in model”| Value | What it calls |
|---|---|
mlx/Jundot/gemma-4-26B-A4B-it-oQ6e-mtp |
One model, by its ID. Copy model id in Models gives it to you. |
coding-local |
A model alias. |
@preset/coder |
A preset: a model with saved settings. |
@route/everyday |
A Smart Route: Nexus picks the model per request. |
@pool/qwen-27b |
A Smart Balancer pool: Nexus picks the machine. |
Streaming, tools and the Responses API work the same way, as long as the model supports them.
Check it worked
Section titled “Check it worked”List what your key can use:
curl http://127.0.0.1:3939/v1/models -H "Authorization: Bearer $NEXUS_API_KEY"Then open Activity → Live stream and run your code. Each request shows up as it happens.
If you get 401, check the key. If you get MODEL_NOT_FOUND, check the model name against /v1/models. More in Gateway.