OpenAI SDK
Call Essevin with the OpenAI Python or Node.js SDK.
Existing OpenAI SDK applications only need a different Base URL, plan key, and model ID. Keep the application's current framework and error handling.
| Item | Value |
|---|---|
| Base URL | https://api.essevin.com/v1 |
| Key environment variable | ESSEVIN_OPENAI_API_KEY |
| Models | GPT, Gemini chat, and other OpenAI-compatible models |
| Model ID | Use an ID returned by GET /v1/models for the selected key |
Keep keys out of source code
Inject ESSEVIN_OPENAI_API_KEY through your deployment platform, a local .env file, or the system environment. Never commit .env or a real key to Git.
Install and send a minimal request
Install the SDK:
python -m pip install openaiSend a request:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.essevin.com/v1",
api_key=os.environ["ESSEVIN_OPENAI_API_KEY"],
)
resp = client.chat.completions.create(
model="gpt-5.6-sol",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)Start with the prompt “Reply only with ok.” Add stream: true only when the application actually uses streaming, then verify that SSE events arrive incrementally.
Stream output and get usage
After passing stream_options.include_usage, the last event has empty choices and its usage field carries the token usage for the request.
stream = client.chat.completions.create(
model="gpt-5.6-sol",
messages=[{"role": "user", "content": "Describe yourself in three sentences"}],
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="", flush=True)
if chunk.usage: # Last event: choices is empty, only usage is set
print()
print(chunk.usage)Tool calls
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Look up the weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "What's the weather like in Shanghai today?"}]
resp = client.chat.completions.create(model="gpt-5.6-sol", messages=messages, tools=tools)
msg = resp.choices[0].message
if msg.tool_calls:
call = msg.tool_calls[0]
print(call.function.name, call.function.arguments)
# Run the tool, then feed the result back; tool_call_id must match the previous call.id
messages += [msg, {"role": "tool", "tool_call_id": call.id, "content": "Sunny, 26°C"}]
resp = client.chat.completions.create(model="gpt-5.6-sol", messages=messages, tools=tools)
print(resp.choices[0].message.content)Timeouts and retries
openai-python defaults to a 600-second read timeout and 2 automatic retries. Use streaming for long outputs;
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.essevin.com/v1",
api_key=os.environ["ESSEVIN_OPENAI_API_KEY"],
timeout=600, # seconds; prefer streaming for long outputs
max_retries=2, # automatic retries for connection errors, 429, and 5xx
)