Use the OpenAI Python SDK with InferGate

Configure the OpenAI Python SDK for InferGate, send a Responses request with gpt-5.5 and inspect text output without exposing your API key.

Install and configure

Use a supported Python version and a current OpenAI SDK release with Responses support. Install in an isolated virtual environment.

python -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade openai
export INFERGATE_API_KEY="YOUR_INFERGATE_API_KEY"

Send a complete response

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["INFERGATE_API_KEY"],
    base_url="https://api.useinfergate.com/v1",
)
response = client.responses.create(
    model="gpt-5.5",
    input="Reply with one sentence about API design.",
    max_output_tokens=256,
)
print(response.output_text)

Validate the result

Check response.status, response.model and response.usage as well as output text. Handle SDK exceptions in the caller. Do not log the client configuration or key. Follow the streaming guide for incremental text.

Official Python SDK · InferGate examples

Python setup: common failure points

Layer or outcomeExpected value or observationAction
Keyos.environ["INFERGATE_API_KEY"]Avoid hardcoding secrets
Client optionbase_urlInclude /v1 once
SDKA release with client.responses supportOlder SDK releases may lack Responses
Resultresponse.output_text and response.statusDo not treat empty output as task success

Frequently asked questions

Why does Python report that responses is missing?

Check the installed package and interpreter in the active virtual environment. Install a current OpenAI SDK release with Responses support, then retry the minimal example.

How do I capture failures without leaking the key?

Catch the SDK exception at your application boundary and record sanitized error details, status and request ID. Do not dump the client object, environment or authorization header.

Can I stream with the Python SDK?

Yes, use the streaming guide for the verified Responses event pattern. The handler must check completion and close the stream when finished.

Continue your integration

Review prepaid pricing · Read API documentation · Get Started

Start with a small request

Create an InferGate account Read API documentation

Explore the API

OpenAI-compatible APIMulti-model APIAI API gateway