Skip to content

Call the API with the OpenAI SDK

View as Markdown

Every text or embedding model on the GenAI API is OpenAI-compatible. Point the OpenAI SDK’s connection settings at the model’s TIR endpoint and your Auth Token, and the rest of your OpenAI code stays the same. The examples call DeepSeek V3, and you can use any model that is available in the GenAI API list. See Is a model on GenAI API guaranteed to stay available?.

The examples use Python, and the same base URL and Auth Token work with the OpenAI JavaScript SDK too.

You need:

pip install -U openai

A text or embedding model’s endpoint already carries the model’s name, so the URL you connect to decides which model you call:

from openai import OpenAI
client = OpenAI(
api_key="<your-auth-token>",
base_url="https://infer.e2enetworks.net/project/<your-project-id>/genai/deepseek_v3/v1",
)

<your-auth-token> is the Auth Token from your Personal Access Token. <your-project-id> is the project the token belongs to. DeepSeek V3’s API name, deepseek_v3, is already in that URL; replace it with the API name of the model you want. A model’s API name can differ from the name shown in the model list.

The OpenAI SDK also needs the model’s API name in each request:

response = client.chat.completions.create(
model="deepseek_v3",
messages=[{"role": "user", "content": "<your prompt>"}],
)
print(response.choices[0].message.content)

(Optional) To get the reply as it is generated instead of waiting for the whole response, turn streaming on and read each chunk’s delta:

stream = client.chat.completions.create(
model="deepseek_v3",
messages=[{"role": "user", "content": "<your prompt>"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")

The model’s reply prints to your console, all at once or piece by piece if you streamed it.

An embedding model works the same way: point the client at its own endpoint and pass its API name as the model. For a worked example, see Generate vector embeddings. A speech or image model takes its name in the request body rather than in the endpoint, so it needs the TIR SDK or the REST API instead; see Call the API with the TIR SDK and Call the API with REST. If a request fails, see Troubleshooting TIR GenAI API.