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.
Before you begin
Section titled “Before you begin”You need:
- A Personal Access Token. See Get started with TIR GenAI API.
- The API name of the text or embedding model you want to call, and your project ID. See Models and calling methods.
Install the OpenAI SDK
Section titled “Install the OpenAI SDK”pip install -U openaiPoint the client at your model
Section titled “Point the client at your model”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.
Send a request
Section titled “Send a request”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="")Read the reply
Section titled “Read the reply”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.