SDKs and frameworks
NezhaGate serves both an OpenAI-compatible API and an Anthropic API, so the official SDKs only need a new base URL and key.
Two base URLs
| Protocol | Base URL | For |
|---|---|---|
| OpenAI | https://nezhagate.com/v1 | Every chat model, plus the image and video endpoints |
| Anthropic | https://nezhagate.com/anthropic | Claude models (the Anthropic SDK adds /v1/messages itself) |
The examples read the key from the NEZHAGATE_API_KEY environment variable; never put a key in code.
OpenAI SDK
import os
from openai import OpenAI
client = OpenAI(base_url="https://nezhagate.com/v1", api_key=os.environ["NEZHAGATE_API_KEY"])
r = client.chat.completions.create(
model="gpt-5.5",
messages=[{"role": "user", "content": "Hello"}],
)
print(r.choices[0].message.content)The OpenAI SDK also reads the OPENAI_BASE_URL and OPENAI_API_KEY environment variables. client.responses.create(...) calls the Responses API, which serves the GPT models only.
Anthropic SDK
import os
from anthropic import Anthropic
client = Anthropic(base_url="https://nezhagate.com/anthropic", api_key=os.environ["NEZHAGATE_API_KEY"])
m = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(next(b.text for b in m.content if b.type == "text"))Point base_url at /anthropic, without /v1. The ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY environment variables work too.
LangChain
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-5.5",
base_url="https://nezhagate.com/v1",
api_key=os.environ["NEZHAGATE_API_KEY"],
use_responses_api=False,
stream_usage=True,
)
print(llm.invoke("Hello").content)LangChain switches some GPT models, or requests with certain parameters, to the Responses API on its own; use_responses_api=False (useResponsesApi: false in JavaScript) keeps it on the chat endpoint. With a custom base_url, streaming returns no usage unless you set stream_usage=True.
Vercel AI SDK
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";
const gw = createOpenAI({ baseURL: "https://nezhagate.com/v1", apiKey: process.env.NEZHAGATE_API_KEY });
const { text } = await generateText({ model: gw.chat("gpt-5.5"), prompt: "Hello" });
console.log(text);Since AI SDK 5, gw("model-id") uses the Responses API; gw.chat("model-id") uses the chat endpoint and works with every model. With @ai-sdk/anthropic, set baseURL to https://nezhagate.com/anthropic/v1 (with /v1).
Troubleshooting
base_url is missing /v1; it should be https://nezhagate.com/v1.
base_url ends in /v1, so requests go to /anthropic/v1/v1/messages. Stop at /anthropic.
The framework may have switched to the Responses API, which serves GPT models only: set use_responses_api=False in LangChain, or use gw.chat(...) in the Vercel AI SDK.