OpenAI-compatible requests¶
UbiOps provides functionality to interface with deployments using the OpenAI format, allowing for easier integrations with frameworks that use this protocol. You can make use of the OpenAI format for deployments with a plain
input type when the input/output configuration of the deployment is set to plain
.
OpenAI makes use of the base_url
and model
tags to specify which models to send requests to. In the context of UbiOps deployments, these can be used to specify which model inside a deployment is requested. The base_url
is used to select the correct project and the model
refers to the deployment and its version within the project.
OpenAI API Reference
For a complete overview of the OpenAI format, see the OpenAI documentation.
Format¶
For models hosted by OpenAI, the base_url
is https://api.openai.com/v1
and an example model
would be gpt-4.5-preview-2025-02-27
. In UbiOps, the format is as follows:
-
base_url
:https://{UBIOPS_API_HOST}/projects/{PROJECT_NAME}/openai-compatible/v1/
-
UBIOPS_API_HOST
: The URL of the UbiOps API, e.g.,api.ubiops.com/v2.1
-
PROJECT_NAME
: The name of the project in which the deployment is created. -
Example:
https://api.ubiops.com/v2.1/projects/my-project/openai-compatible/v1/
-
-
model
:ubiops-deployment/{DEPLOYMENT_NAME}/{VERSION_NAME}/{MODEL_NAME}
-
DEPLOYMENT_NAME
: The name of the deployment. -
VERSION_NAME
: The name of the deployment version. Leave blank when requesting thedefault
version. -
MODEL_NAME
: The name of the model as defined in your deployment code. -
Example:
ubiops-deployment/my-deployment/my-version/my-model
orubiops-deployment/my-deployment//my-model
for using the default version of a deployment.
-
OpenAI Deployment Format
Note that you are responsible for ensuring that the deployment can accept the OpenAI format.
For an example on setting up such a deployment that can be requested with an openai
client, see the vLLM Deployment tutorial.
Supported OpenAI endpoints
The following endpoints are supported for OpenAI requests:
/v1/chat/completions
/v1/embeddings
Authentication¶
For authentication to the UbiOps API via the OpenAI client, you can use a standard UbiOps API token (e.g. "Token a1b2c3d4e5f6"). However, the OpenAI client doesn't accept token prefixes. The prefix Token
should therefore be removed. This means that the provided api_key
should look like e.g. "a1b2c3d4e5f6". See the Python example for more information.
Example¶
We'll show 2 different examples on how to make an OpenAI request to a UbiOps deployment. One of the examples will be using the OpenAI
Python client and the other will be using curl
.
Do note that the deployment needs to accept the OpenAI format for the requests to complete succesfully.
Python¶
from openai import OpenAI
ubiops_token = "Token ..."
project_name = "openai-project"
deployment_name = "openai-deployment"
version_name = "" # Send request to the default version
model_name = "test-model"
# Generate the OpenAI client
client = OpenAI(
api_key=ubiops_token[6:] if ubiops_token.startswith("Token ") else ubiops_token,
base_url=f"https://api.ubiops.com/v2.1/projects/{project_name}/openai-compatible/v1"
)
# Send a (streaming) request to the deployment
response = client.chat.completions.create(
model=f"ubiops-deployment/{deployment_name}/{version_name}/{model_name}",
messages=[{"role": "user", "content": "Can you tell me more about UbiOps in exactly two lines"}],
stream=True
)
Curl¶
curl -X POST "https://api.ubiops.com/v2.1/projects/<project-name>/openai-compatible/v1/chat/completions" \
-H "Authorization: Token ..." \
-H "Content-Type: application/json" \
-d '{
"model": "ubiops-deployment/<deployment-name>/<version-name>/<model-name>",
"messages": [{"role": "user", "content": "Can you tell me more about UbiOps in exactly two lines"}],
"stream": false,
}'