OpenAI Proxy API
This endpoint proxies all OpenAI API requests, supporting multi-tenant authentication and dynamic path forwarding. It is compatible with standard OpenAI APIs such as chat/completions and responses, and automatically handles authentication and client isolation.
1. Endpoint
Supports all HTTP methods
/api/openai/[...path]
Examples:
/api/openai/v1/chat/completions/api/openai/v1/audio/speech/api/openai/v1/responses
2. Auth & Headers
- Required: Firebase Token or custom authentication (handled automatically, no need to provide OpenAI Key manually)
- Cookies and authorization headers are removed;
Authorization: Bearer <OpenAI API Key>is added automatically
3. Request Body
- Follows OpenAI official API format, supports raw JSON or streaming body
- Directly forwarded, no extra wrapping needed
4. Status Codes
| Code | Meaning |
|---|---|
| 200 | Success, returns OpenAI response as-is |
| 401 | Authentication failed { "error": "Authentication failed" } |
| 500 | Server error { "error": "Client ID not found" } or { "error": "OpenAI API key not found" } |
5. Path & Forwarding Rules
- Dynamically extracts everything after
/api/openai/and forwards tohttps://api.openai.com/ - If path is empty, defaults to
v1/responses
6. Streaming & JSON Support
- Supports OpenAI streaming responses (SSE), body is forwarded as-is
- Supports standard JSON responses, headers are consistent with OpenAI
7. Error Handling
- Authentication failure, missing Client ID, or missing OpenAI Key all return standard JSON errors
- OpenAI API errors are forwarded with original content and status code
8. Example curl
Streaming request:
curl -N \
-H "Authorization: Bearer <Firebase Token>" \
-H "Content-Type: application/json" \
https://your-host/api/openai/v1/chat/completions \
-d '{"messages":[{"role":"user","content":"Hello"}]}'
9. Design Notes
- Multi-tenant isolation: Each request automatically identifies clientId to prevent cross-tenant access
- Unified authentication: Single entry, supports multiple token types
- Security: Sensitive headers are removed, only necessary information is retained
- Performance: Supports streaming forwarding, suitable for large model scenarios
10. Error Examples
{ "error": "Authentication failed" }
{ "error": "Client ID not found" }
{ "error": "OpenAI API key not found" }
{ "error": "OpenAI proxy internal error", "details": "..." }