TensorZero Autopilot is an automated AI engineer that analyzes LLM observability data, optimizes prompts and models, sets up evals, and runs A/B tests. Schedule a demo →
Let’s initialize the OpenAI SDK and point it to the gateway we just launched.
from openai import OpenAIclient = OpenAI(base_url="http://localhost:3000/openai/v1", api_key="not-used")
6
Call the LLM
OpenAI web search can take up to a minute to complete.
response = client.chat.completions.create( model="tensorzero::model_name::gpt-5-mini-responses-web-search", messages=[ { "role": "user", "content": "What is the current population of Japan?", } ],)
Sample Response
ChatCompletion( id='0199ff78-5bad-7312-ab13-e4c5fa0bde8d', choices=[ Choice( finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage( content="Short answer — it depends on the source/date:\n\n- Japan's official demographic survey (Ministry of Internal Affairs and Communications, reported by major Japanese outlets) shows a total population of 124,330,690 as of January 1, 2025 (this includes foreign residents). ([asahi.com](https://www.asahi.com/ajw/articles/15952384?utm_source=openai))\n\n- International mid‑year estimates (United Nations/UNFPA) put Japan's 2025 population at about 123.1 million (mid‑2025 estimate), which uses a different methodology and reference date. ([unfpa.org](https://www.unfpa.org/data/world-population/JP?utm_source=openai))\n\nToday is October 20, 2025 — would you like me to fetch a live or another specific estimate (e.g., UN mid‑year, World Bank, or the latest Japanese government update)?", refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=[] ) ) ], created=1760927745, model='tensorzero::model_name::gpt-5-mini-responses-web-search', object='chat.completion', service_tier=None, system_fingerprint='', usage=CompletionUsage( completion_tokens=2304, prompt_tokens=21444, total_tokens=23748, completion_tokens_details=None, prompt_tokens_details=None ), episode_id='0199ff78-5bad-7312-ab13-e4d8708e5b73')
You can point the OpenAI Node SDK to a TensorZero Gateway to access the Responses API.
1
Set up your OpenAI API key
You can set the OPENAI_API_KEY environment variable with your API key.
export OPENAI_API_KEY="sk-..."
2
Install the OpenAI Node SDK
You can install the OpenAI SDK with a package manager like npm.
npm i openai
3
Configure a model for the OpenAI Responses API
Create a configuration file with a model using api_type = "responses" and provider tools:
Let’s initialize the OpenAI SDK and point it to the gateway we just launched.
import OpenAI from "openai";const client = new OpenAI({ baseURL: "http://localhost:3000/openai/v1", apiKey: "not-used",});
6
Call the LLM
OpenAI web search can take up to a minute to complete.
const response = await client.chat.completions.create({ model: "tensorzero::model_name::gpt-5-mini-responses-web-search", messages: [ { role: "user", content: "What is the current population of Japan?", }, ],});
Sample Response
{ id: '0199ff74-0203-70d1-857a-a52b89291955', episode_id: '0199ff74-0203-70d1-857a-a53eb122c72f', choices: [ { index: 0, finish_reason: 'stop', message: { content: 'According to Japan’s Statistics Bureau, the preliminary population count was 12,317 ten‑thousand (i.e., 123,170,000) as of September 1, 2025. ([stat.go.jp](https://www.stat.go.jp/english/?s=1&vm=r))\n' + '\n' + 'Would you like a mid‑year UN estimate or the latest monthly update?', tool_calls: [], role: 'assistant' } } ], created: 1760927476, model: 'tensorzero::model_name::gpt-5-mini-responses-web-search', system_fingerprint: '', service_tier: null, object: 'chat.completion', usage: { prompt_tokens: 32210, completion_tokens: 2253, total_tokens: 34463 }}