OpenAI¶
Point any OpenAI-compatible client at Privyx. In the default transparent mode
only the base URL changes: every path is forwarded, and the client's own
Authorization header goes upstream unless Privyx holds a key.
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1") # the key still comes from OPENAI_API_KEY
reply = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Write a short greeting to alice@example.com"}],
)
print(reply.choices[0].message.content)
Start it with:
privyx proxy --upstream https://api.openai.com
Streaming, tool calls, and the Responses API are shown in An app on the OpenAI or Anthropic SDK, and Codex in Coding agents.
Privyx masks the request, forwards it to OpenAI, and restores the reply,
streamed or not, tool-call arguments included. It masks
/v1/chat/completions, the legacy /v1/completions, /v1/embeddings, and
the Responses API. An embeddings reply holds only vectors,
so it is returned as it is; see Embeddings.
Configuration¶
Transparent mode needs no config file. provider: openai selects the
built-in provider openai, which makes OpenAI the upstream when --upstream
is not given: transparent mode uses the origin of base_url, and gateway mode
posts to it as written. Written out, with its default:
provider: openai
providers:
openai:
type: openai
base_url: https://api.openai.com/v1/chat/completions
Credential settings can read environment variables, such as
api_key: ${OPENAI_API_KEY}. A missing variable stops startup; see
Configuration.
Privyx's own key is, in both modes, the api_key of the provider in use;
PRIVYX_OPENAI_API_KEY sets it for the built-in provider openai, which
sends it to api.openai.com only. When one is set it replaces the client's
key on every request; when none is, the transparent proxy relays the client's
own Authorization header and the gateway sends none.
What is covered¶
Every string in messages is masked, except under keys that hold no prose,
such as ids, role, type, name, image_url, and base64 data; the full
rule is in
Proxy architecture.
That covers content (a string or parts, refusal parts included),
refusal, reasoning_content and the non-standard reasoning (OpenRouter,
vLLM, Ollama), tool_calls[].function.arguments and the legacy
function_call.arguments (parsed as JSON and masked value by value), and
prediction.content. In tools, only the function and parameter
descriptions are masked; response_format, metadata, user, and the rest
of the top level are left alone. In a batch reply, every string is restored.
Streaming¶
In a stream, content, reasoning_content, reasoning, and refusal in
choices[0].delta are each restored separately as they arrive. The arguments
of tool_calls and the legacy function_call are collected and delivered
restored as one complete call. Every other chunk (role, finish_reason,
usage) has each of its strings restored.
Responses API¶
/v1/responses is masked with the responses schema, and so are
/v1/responses/input_tokens and /v1/responses/compact, which take the same
body. It is the API Codex speaks, so privyx run codex is covered.
- Request.
instructions,prompt.variables, andinput, a string or a list of items, are masked: messageinput_text/output_text,reasoningsummaries and content (encrypted_contentis opaque and kept),function_call.arguments(parsed JSON),function_call_output.output,custom_tool_callinput / output,local_shell_call.action.command, shell outputstdout/stderr,apply_patch_call.operation.diff,mcp_callarguments/output, and any string field added later. Top-leveltext,reasoning, andtool_choiceare config and left alone; so istools, apart from itsdescriptionstrings. - Stream. Every event with a string
delta(output_text,refusal,reasoning_summary_text,reasoning_text,audio.transcript, and others) is restored separately for each kind anditem_id,output_index,content_index, andsummary_index.function_call_arguments,mcp_call_arguments, andcustom_tool_call_inputare buffered and emitted as one restored delta just before their.done. The full text is repeated in*.done,content_part.done,output_item.done, andresponse.completed, which clients such as Codex build their history from, so those are restored too, with theirevent:lines kept. A flushed tail reuses its template'ssequence_number. - Server-side history.
previous_response_idwithstore: truekeeps earlier turns on the provider, with tokens in them; see Proxy architecture for when those tokens keep their meaning.