OpenModelOpenModel
SDKs & Libraries

OpenAI SDK

Use the official OpenAI SDK to call the OpenModel Responses API

The official OpenAI SDK can call OpenModel's Responses API through client.responses.create. This guide covers only the Responses protocol; OpenModel does not provide the Chat Completions API or other OpenAI API endpoints.

Installation

pip install openai

Configuration

Python

from openai import OpenAI

client = OpenAI(
    base_url="https://api.openmodel.ai/v1",
    api_key="om-your-api-key",
)

Node.js

import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://api.openmodel.ai/v1",
  apiKey: "om-your-api-key",
})

Environment Variables

You can also configure the SDK using environment variables, which keeps credentials out of your source code:

export OPENAI_BASE_URL="https://api.openmodel.ai/v1"
export OPENAI_API_KEY="om-your-api-key"

Then initialize the client without explicit parameters:

from openai import OpenAI

client = OpenAI()  # Reads from environment variables

Model Names

Choose a model from the dynamic model data in the Console and make sure its supported_protocols includes responses. Use the model name exactly as shown. For example:

  • gpt-5.4

Examples

Basic Response

from openai import OpenAI

client = OpenAI(
    base_url="https://api.openmodel.ai/v1",
    api_key="om-your-api-key",
)

response = client.responses.create(
    model="gpt-5.4",
    input="Explain quantum computing in simple terms.",
)

print(response.output_text)

Streaming

from openai import OpenAI

client = OpenAI(
    base_url="https://api.openmodel.ai/v1",
    api_key="om-your-api-key",
)

stream = client.responses.create(
    model="gpt-5.4",
    input="Write a short story about a robot learning to paint.",
    stream=True,
)

for event in stream:
    if hasattr(event, "delta") and event.delta:
        print(event.delta, end="", flush=True)
print()

Multi-Turn Conversation

from openai import OpenAI

client = OpenAI(
    base_url="https://api.openmodel.ai/v1",
    api_key="om-your-api-key",
)

response = client.responses.create(
    model="gpt-5.4",
    instructions="You are a helpful math tutor.",
    input=[
        {
            "role": "user",
            "content": "What is the derivative of x^3?",
        },
        {
            "role": "assistant",
            "content": "The derivative of x^3 is 3x^2.",
        },
        {
            "role": "user",
            "content": "What about the integral?",
        },
    ],
)

print(response.output_text)

Tool Use (Function Calling)

from openai import OpenAI

client = OpenAI(
    base_url="https://api.openmodel.ai/v1",
    api_key="om-your-api-key",
)

tools = [
    {
        "type": "function",
        "name": "get_weather",
        "description": "Get the current weather for a location.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "City and country, e.g. 'Tokyo, Japan'",
                },
            },
            "required": ["location"],
        },
    },
]

response = client.responses.create(
    model="gpt-5.4",
    input="What's the weather like in San Francisco?",
    tools=tools,
)

for item in response.output:
    if item.type == "function_call":
        print(f"Function: {item.name}")
        print(f"Arguments: {item.arguments}")

Async Usage (Python)

import asyncio
from openai import AsyncOpenAI

client = AsyncOpenAI(
    base_url="https://api.openmodel.ai/v1",
    api_key="om-your-api-key",
)

async def main():
    response = await client.responses.create(
        model="gpt-5.4",
        input="Hello!",
    )
    print(response.output_text)

asyncio.run(main())

Error Handling

The OpenAI SDK raises typed exceptions that you can catch and handle:

from openai import OpenAI, APIConnectionError, APIStatusError, APITimeoutError

client = OpenAI(
    base_url="https://api.openmodel.ai/v1",
    api_key="om-your-api-key",
)

try:
    response = client.responses.create(
        model="gpt-5.4",
        input="Hello!",
    )
except APIConnectionError:
    print("Connection failed. Check your network.")
except APITimeoutError:
    print("Request timed out.")
except APIStatusError as e:
    print(f"API error {e.status_code}: {e.message}")

For comprehensive error handling patterns, see Error Handling.

Next Steps

On this page