--- title: "Call the API with the OpenAI SDK" description: "Call a GenAI API text or embedding model from your own code with the OpenAI SDK, using your Auth Token and the model's TIR endpoint." content_type: "how-to" product: "genai-api" platform: "TIR" url: "/tir/genai-api/how-to/call-the-api-with-the-openai-sdk/" topic: ["call-the-api"] --- # Call the API with the OpenAI SDK 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?](/tir/genai-api/faq/#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 You need: - A Personal Access Token. See [Get started with TIR GenAI API](/tir/genai-api/get-started/). - The API name of the text or embedding model you want to call, and your project ID. See [Models and calling methods](/tir/genai-api/concepts/models-and-calling-methods/). ## Install the OpenAI SDK ```bash pip install -U openai ``` ## 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: ```python from openai import OpenAI client = OpenAI( api_key="", base_url="https://infer.e2enetworks.net/project//genai/deepseek_v3/v1", ) ``` `` is the Auth Token from your Personal Access Token. `` 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 The OpenAI SDK also needs the model's API name in each request: ```python response = client.chat.completions.create( model="deepseek_v3", messages=[{"role": "user", "content": ""}], ) 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: ```python stream = client.chat.completions.create( model="deepseek_v3", messages=[{"role": "user", "content": ""}], stream=True, ) for chunk in stream: print(chunk.choices[0].delta.content or "", end="") ``` ## 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](/tir/genai-api/how-to/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](/tir/genai-api/how-to/call-the-api-with-the-tir-sdk/) and [Call the API with REST](/tir/genai-api/how-to/call-the-api-with-rest/). If a request fails, see [Troubleshooting TIR GenAI API](/tir/genai-api/troubleshooting/genai-api/).