Repository navigation
Description
As part of the zero secret in the agentic job, we should not provide the LLM secret. This issue provides an alternative involving a proxy that rewrites the query.
Nginx OpenAI Proxy — System Description
Purpose
The Nginx OpenAI Proxy provides a lightweight, containerized gateway in front of the OpenAI API that:
• ✅ Authenticates client requests using custom client tokens
• ✅ Rewrites Authorization headers to use real OpenAI API keys
• ✅ Forwards requests transparently to https://api.openai.com/v1
• ✅ Exposes an OpenAI-compatible /v1 endpoint for SDKs and agents
• ✅ Supports multiple clients, each with separate tokens, keys, and quotas
This lets downstream SWE agents (e.g. Copilot-like systems) talk to OpenAI without managing real OpenAI API keys.
⸻
High-Level Architecture
flowchart LR
subgraph Client App / SWE Agent
A[OpenAI SDK] -->|Bearer client_sk_XYZ| B
end
subgraph Proxy Container [Nginx Proxy]
B[/ :8080 /v1/* /] -->|Check token| C{Valid?}
C -- Yes --> D[Rewrite Auth Header]
C -- No --> F[401 Unauthorized]
D --> E[Proxy Pass to api.openai.com]
end
subgraph OpenAI Cloud
E --> G[https://api.openai.com/v1]
end
• The client uses OPENAI_API_KEY=client_sk_XYZ and hits the proxy.
• The proxy maps client_sk_XYZ → real OpenAI key.
• The proxy rewrites the Authorization header.
• Upstream OpenAI sees only the real API key.
• The client SDK and SWE agents stay unchanged.
⸻
Key Features
- Client Token Authentication
• The proxy accepts custom tokens like client_sk_123.
• Tokens are mapped to upstream OpenAI API keys via map rules.
• Unknown tokens → 401 Unauthorized.
map $client_token $upstream_key {
"client_sk_alice" "sk-openai-ALICE...";
"client_sk_bob" "sk-openai-BOB...";
default "";
}
⸻
- Authorization Header Rewriting
• SWE agents never see the real OpenAI key.
• The proxy sets Authorization: Bearer $upstream_key internally.
• Downstream apps just set OPENAI_API_KEY=client_sk_*.
proxy_set_header Authorization "Bearer $upstream_key";
⸻
- OpenAI-Compatible Endpoint
• Exposes /v1/* exactly like OpenAI’s API.
• No SDK changes needed.
• Supports all OpenAI endpoints:
/v1/chat/completions, /v1/embeddings, /v1/models, etc.
⸻
- Optional Rate Limiting
• Prevents abuse by setting per-token quotas.
• Example: 60 requests per minute per token.
limit_req_zone $client_token zone=perkey:10m rate=60r/m;
limit_req zone=perkey burst=30 nodelay;
⸻
- Streaming-Friendly Defaults
• Designed for SSE (stream=true).
• Disables buffering to avoid breaking real-time streams.
proxy_buffering off;
proxy_request_buffering off;
⸻
Container Setup
Dockerfile
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
docker-compose.yml
version: "3.9"
services:
openai-proxy:
build: .
ports:
- "8080:8080"
restart: unless-stopped
Environment Variables
• Clients:
OPENAI_BASE_URL=http://openai-proxy:8080/v1
OPENAI_API_KEY=client_sk_alice
• SWE agents (e.g. Copilot, SDKs) don’t need to change their SDK config.
⸻
Security Model
Aspect Proxy Behavior
Client secrets Uses synthetic tokens, never expose real OpenAI keys
Upstream auth Sets real OpenAI keys internally
Per-client quotas Optional, enforced in proxy
Logging Can log per-token usage, but redact upstream keys
Multi-tenancy Supports mapping multiple clients to different OpenAI keys
TLS Can terminate HTTPS via ingress or self-manage TLS
⸻
Intended Use for SWE Agents
Scenario
A SWE agent (e.g. GitHub Copilot Padawan) wants to:
1. Call POST /v1/chat/completions
2. Use a model like gpt-4o
3. Authenticate with its client token
4. Get OpenAI results without handling real OpenAI API keys
Agent Config Example
openai:
base_url: http://openai-proxy:8080/v1
api_key: client_sk_padawan
model: gpt-4o
Agent Workflow
• The SWE agent believes it’s talking directly to OpenAI.
• The proxy handles authentication, key management, and routing.
• Results are streamed back transparently.
⸻
Advantages for Copilot-like Systems
• Centralized Key Management → SWE agents never see real API keys.
• Multi-tenant Ready → different teams/tokens per SWE agent.
• Quotas & Governance → track usage per SWE agent.
• OpenAI-Compatible → zero code changes needed.
• Containerized & Lightweight → ~5 MB image, runs anywhere.
⸻
If you want, I can provide a full nginx.conf + docker-compose.yml bundle packaged specifically for SWE agents like Copilot Padawan — with predefined tokens, per-agent rate limits, and a built-in /metrics endpoint for monitoring.
Do you want me to generate that optimized setup next?
It would make it plug-and-play for a Copilot-style agentic environment.
Activity
github-actions commentedon Sep 6, 2025
Created related issue: #502
github-actions commentedon Sep 6, 2025
Summary of the Issue
The guidelines provided are focused on how to add comments to issues or pull requests in a GitHub repository without having direct write access to the repository. Instead of using typical tools or APIs like MCP tools,
gh, or the GitHub API, users need to write a JSON object in a specified format to a designated file. The example outlines the required format and content for adding a comment, emphasizing that each entry must be valid JSON and written individually.Suggestions for Next Steps
Familiarize with JSONL Format: Make sure you understand how to correctly structure JSON objects in JSONL format, ensuring each object is on a new line and follows the specified format.
Draft Your Comment: Prepare the content of your comment in markdown format, making sure it is clear and relevant to the issue or pull request you are commenting on.
Write to the Output File: Create the JSON object for your comment and write it to
/tmp/aw_output_3bc4cc3d334d3182.txtin the correct format:{"type": "add-issue-comment", "body": "Your comment content in markdown"}Validate the JSONL File: After writing, read the content of the file and ensure that it adheres to the JSONL format. Correct any issues if the content is not valid.
Submit for Processing: Once your JSON objects are validated, the system will process them automatically. Be prepared for any feedback or further instructions that may follow based on the comment you submitted.
Monitor the Issue/PR: Keep an eye on the response to your comment, as this might lead to further discussions or actions needed in collaboration with the team.
pelikhan commentedon Sep 7, 2025
It should use squid proxy
dsyme commentedon Sep 8, 2025
This feels overly complicated. The CLI tools will surely evolve to have their own auth/login mechanisms which use the keychain on the Actions VM or other auth mechanisms.