OpenAI SDK
Use the official OpenAI SDK for Python or Node with Nexrouting: set the base URL and your key, and every model works.
De documentatie is in het Engels.
The OpenAI SDKs work with Nexrouting as they are. Set the base URL to https://api.nexrouting.com/v1 and use your Nexrouting key. Any model that lists /v1/chat/completions in GET /v1/models works this way, Claude and Gemini models included.
Install
pip install openaiChat completions
import osfrom openai import OpenAI client = OpenAI( base_url="https://api.nexrouting.com/v1", api_key=os.environ["NEXROUTING_API_KEY"],) reply = client.chat.completions.create( model="openai/gpt-6-astra", messages=[{"role": "user", "content": "Hello"}],)print(reply.choices[0].message.content)The base URL also works as https://nexrouting.com/api/v1, for networks that only allow the main domain.
Configure with environment variables
Both SDKs read OPENAI_BASE_URL and OPENAI_API_KEY. With these set, existing code runs on Nexrouting without changes; only the model IDs need the provider/ part.
export OPENAI_BASE_URL="https://api.nexrouting.com/v1"export OPENAI_API_KEY="$NEXROUTING_API_KEY"Streaming
Pass stream=True and read the chunks. Add stream_options to get the token counts in the last chunk; see Streaming.
stream = client.chat.completions.create( model="openai/gpt-6-astra", messages=[{"role": "user", "content": "Write a haiku about routing."}], stream=True, stream_options={"include_usage": True},)for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="") if chunk.usage: print("\n", chunk.usage)Responses API
Models that list /v1/responses in their endpoints accept the Responses API. A few models, such as some OpenAI pro models, are only available there.
response = client.responses.create( model="openai/gpt-6-astra", input="Explain routing in one sentence.",)print(response.output_text)Embeddings
result = client.embeddings.create( model="openai/text-embedding-3-small", input=["first text", "second text"],)print(len(result.data[0].embedding))List the models
client.models.list() calls GET /v1/models and works as usual. Each entry has extra fields such as pricing, lane and endpoints; see List models.
Errors and retries
Errors use the OpenAI shape, so the SDK raises its usual exceptions: AuthenticationError for 401, PermissionDeniedError for 403, NotFoundError for 404, RateLimitError for 429 and APIStatusError for the rest, such as 402 insufficient_credits. The SDK retries 429 and 5xx responses by itself. See Errors.
Not available
Files, batches, fine-tuning, assistants, moderations, image generation, audio and realtime are not available. Those paths return 404 not_found.