Call Confidential Inference from LangChain
Use ChatOpenAI from langchain-openai (Python) or @langchain/openai (JavaScript) with base URL https://api.confidential.ai/v1 to run LangChain chains and agents on confidential inference.
LangChain's OpenAI chat model works against Confidential Inference. Set the base URL and API key; chains, tools and agents built on ChatOpenAI run unchanged.
Prerequisites
- A Confidential AI API key. Keys are issued by email: request access or write to hello@confidential.ai.
CONFIDENTIAL_API_KEYset in your environment.- Python 3.10+ or Node.js 22+.
Checked on 2 November 2026 with Python langchain-openai 1.7.3 and Node.js @langchain/openai 1.8.0.
Create the chat model
Python:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
base_url="https://api.confidential.ai/v1",
api_key=os.environ["CONFIDENTIAL_API_KEY"],
)
print(llm.invoke("Explain remote attestation in one sentence.").content)JavaScript:
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "deepseek-ai/DeepSeek-V4.1-Flash-1017",
apiKey: process.env.CONFIDENTIAL_API_KEY,
configuration: { baseURL: "https://api.confidential.ai/v1" },
});
const msg = await llm.invoke("Explain remote attestation in one sentence.");
console.log(msg.content);Use an exact model ID from GET /v1/models.
Use it in chains and agents
llm is a standard LangChain chat model: pass it to prompts, bind_tools, with_structured_output or an agent constructor as you would any ChatOpenAI instance. Tool calling and JSON schema output are supported: 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 configuration.baseURL in JavaScript 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
invoke returns an AIMessage with content. For a 401, read the error code: invalid_api_key indicates an authentication failure; model_not_authorized means a listed model ID is required.
Prompts are protected from our side of the connection. Anything your chain logs or traces (for example to a tracing service) leaves your process in plaintext, so treat tracing as part of your own trust boundary.