Call Confidential Inference from the OpenAI SDK

Point the official OpenAI Python or Node.js client at https://api.confidential.ai/v1 and keep the rest of your code. Chat, streaming, structured output and tools work unchanged.

Confidential Inference is OpenAI-compatible. The OpenAI SDK works with two changes: the base URL and the API key.

Prerequisites

Checked on 2 November 2026 with Python openai 2.54.0 and Node.js openai 7.47.0.

Install the client

pip install openai
npm install openai

Set the key and base URL

export CONFIDENTIAL_API_KEY='<API_KEY>'
SettingValue
Base URLhttps://api.confidential.ai/v1
API keyyour Confidential AI key, sent as Authorization: Bearer
Modelan exact ID from GET /v1/models, e.g. deepseek-ai/DeepSeek-V4.1-Flash-1017

Make a request

Python:

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.confidential.ai/v1",
    api_key=os.environ["CONFIDENTIAL_API_KEY"],
)

resp = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
    messages=[{"role": "user", "content": "Explain remote attestation in one sentence."}],
)
print(resp.choices[0].message.content)

Node.js:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.confidential.ai/v1",
  apiKey: process.env.CONFIDENTIAL_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "deepseek-ai/DeepSeek-V4.1-Flash-1017",
  messages: [{ role: "user", content: "Explain remote attestation in one sentence." }],
});
console.log(resp.choices[0].message.content);

Stream the response

stream = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
    messages=[{"role": "user", "content": "Count to five."}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

response_format (JSON and strict JSON schema) and tools work as in the OpenAI API. Field details: API reference.

Verify before sending sensitive input

The client does not check attestation. Follow the attestation guide to configure and start TEErminator with the reviewed production pins. Before sending sensitive input, change base_url in Python or baseURL in Node.js to http://127.0.0.1:8080/v1. Keep the same API key. TEErminator verifies the upstream connection before forwarding requests.

How you know it worked

The request returns a normal chat completion. For a 401, read the error code: invalid_api_key indicates an authentication failure; model_not_authorized means the model is not in the configured inference list. Use an exact ID from GET /v1/models.