Skip to main content

How it works

OpenAI uses proxy mode. After calling patch_openai(), the Python SDK rewrites openai.base_url to point to the Cognisafe Go proxy (http://localhost:8080 by default). All OpenAI client calls then flow through the proxy, which:
  1. Forwards the request to https://api.openai.com unchanged
  2. Streams the response back to your application
  3. Logs the full request and response payload asynchronously — no impact on latency
Because the Cognisafe proxy is OpenAI-compatible, any library that accepts a base_url parameter works automatically — you don’t need to use the official openai Python package.

Setup

Supported capabilities

Streaming responses are buffered by the proxy and logged once the stream closes. Your application receives the stream in real time — only the logging is deferred to stream completion.

Azure OpenAI

For Azure OpenAI, use the same patch_openai() call. The proxy sits in front of Azure’s endpoint rather than https://api.openai.com. Set UPSTREAM_URL on the proxy to your Azure resource URL:
Then configure the SDK normally:
See the Azure OpenAI provider page for full details.

Any OpenAI-compatible library

Because the proxy speaks the OpenAI API protocol, any client that accepts a custom base URL works without patch_openai():