Skip to content

Custom integration

Compatibility boundary

A custom integration is compatible with Nexus when it can set:

  • https://api.nexus-hub.ru/v1 for OpenAI Chat or Responses;
  • https://api.nexus-hub.ru for Anthropic Messages;
  • https://api.nexus-hub.ru/v1beta for Gemini-compatible routes;
  • Bearer or another supported API-key header;
  • a model from GET /v1/models;
  • JSON and, when needed, SSE streaming.

OpenAI Python SDK

The official SDK accepts base_url and api_key:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["NEXUS_API_KEY"],
    base_url="https://api.nexus-hub.ru/v1",
)
response = client.responses.create(
    model=os.environ["NEXUS_MODEL"],
    input="Reply exactly OK.",
    max_output_tokens=16,
)
print(response.output_text)

Set NEXUS_MODEL to a value from GET /v1/models. For Chat Completions, use client.chat.completions.create and its matching output limit.

Anthropic Python SDK

For Messages, set base_url without /v1:

import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ["NEXUS_API_KEY"],
    base_url="https://api.nexus-hub.ru",
)
message = client.messages.create(
    model=os.environ["NEXUS_MODEL"],
    max_tokens=16,
    messages=[{"role": "user", "content": "Reply exactly OK."}],
)
print(message.content)

Retries, timeouts, and streaming

Set a timeout explicitly and retry only errors that are safe to retry in your business logic. Do not retry with the same x-request-id. For streaming, consume SSE through its terminal event and close the connection on error; do not write bodies to logs.

Key hygiene and operations

  • Keep the key in an environment variable or secret manager.
  • Do not commit it or include it in exceptions, traces, screenshots, or prompts.
  • Revoke a compromised key and create a new one.
  • Send support only the method, route, error code, SDK version, and x-request-id.

Official SDKs: openai-python and anthropic-sdk-python. Route fields are documented in the Nexus API reference.