Skip to main content

OpenAI Python SDK Compatibility

For new Python integrations, use the official inertialai-python client.

This page is for teams that already standardize on the OpenAI client and want to point it at InertialAI's embeddings endpoint.

When to use this path

Use the OpenAI SDK if you already have framework code, shared abstractions, or existing tooling built on openai.

Use the official SDK instead if you want:

  • native EmbeddingMultiModalInput models
  • no manual json.dumps() serialization
  • InertialAI-specific exceptions
  • first-class sync and async clients designed for this API

Installation

pip install openai

Basic Setup

Configure the OpenAI client to point to InertialAI's API route:

import os
from openai import OpenAI

client = OpenAI(
base_url="https://inertialai.com/api/v1",
api_key=os.environ["INERTIALAI_API_KEY"]
)

Multi-Modal Input Format

InertialAI's API accepts:

  • Time-series only: Numerical sensor or time-series data without text
  • Text only: Descriptive text without time-series data
  • Multi-modal: Time-series data combined with text for enriched context

Because the OpenAI SDK's embeddings.create() method expects string input, multi-modal payloads must be serialized with json.dumps() before you send them.

import json

embedding_input = [
{
"time_series": [
[34.61, 35.11, 35.21, 35.36, 35.25], # Channel 1
[42.13, 42.45, 42.67, 42.89, 43.01] # Channel 2
],
"text": "Standing jump trial, accelerometer data attached."
}
]

# Stringify the input for OpenAI SDK compatibility
response = client.embeddings.create(
model="inertial-embed-alpha",
input=json.dumps(embedding_input)
)

embedding_vector = response.data[0].embedding

Complete Example

import json
import os
from openai import OpenAI

client = OpenAI(
base_url="https://inertialai.com/api/v1",
api_key=os.environ["INERTIALAI_API_KEY"]
)

embedding_input = [
{
"time_series": [
[34.61, 35.11, 35.21, 35.36, 35.25]
],
"text": "Standing jump trial, accelerometer data attached."
}
]

response = client.embeddings.create(
model="inertial-embed-alpha",
input=json.dumps(embedding_input)
)

embedding = response.data[0].embedding
print(f"Embedding dimensions: {len(embedding)}")
print(f"First 5 values: {embedding[:5]}")
print(f"Tokens used: {response.usage.total_tokens}")

Limitations compared to the official SDK

Capabilityinertialai-pythonOpenAI SDK
Multi-modal inputs without manual serializationYesNo
Typed EmbeddingMultiModalInput modelsYesNo
InertialAI-specific exceptionsYesNo
Native sync and async clients tailored to InertialAIYesPartial
Compatible with existing OpenAI abstractionsNoYes

Error handling

from openai import APIError, AuthenticationError, OpenAIError

try:
response = client.embeddings.create(
model="inertial-embed-alpha",
input=json.dumps(embedding_input)
)
embeddings = [item.embedding for item in response.data]

except AuthenticationError:
print("Invalid API key - check INERTIALAI_API_KEY environment variable")

except APIError as e:
print(f"API error: {e.status_code} - {e.message}")

except OpenAIError as e:
print(f"OpenAI SDK error: {e}")

Choosing between the two clients

  • Choose inertialai-python for new Python work.
  • Choose the OpenAI SDK only when compatibility with existing OpenAI-based code matters more than typed InertialAI-native ergonomics.

Next steps