The AI proxy (https://ai.3bapi.com) is a thin, vendor-agnostic pass-through to
the major AI providers. Front-end applications call the proxy instead of calling a
vendor directly, so the vendor API key is never exposed in the browser.
The proxy holds no vendor keys of its own. The caller sends its own vendor key in encrypted form in a header; the proxy calls the vendor with the request body passed through verbatim and returns the vendor's response unchanged.
A browser app that called OpenAI, Anthropic or another vendor directly would have to ship the plain API key to the client. With the proxy, the browser only holds the encrypted form of the key. The request and response shapes are the vendor's own, so client SDKs work with minimal changes: point them at the proxy and add the headers.
| Method + path | Purpose |
|---|---|
POST /ai |
The proxy. Forwards the body to the selected vendor. |
GET /health |
Health check → { "success": true }. |
POST https://ai.3bapi.com/ai
Content-Type: application/json
x-api-key: <encrypted vendor API key>
x-ai-vendor: claude
x-user-id: 005XXXXXXXXXXXX
x-org-id: 00DXXXXXXXXXXXX
| Header | Required | Purpose |
|---|---|---|
x-api-key |
yes | The vendor API key, in encrypted form. |
x-ai-vendor |
no | openai (default), azure, gemini, or claude. |
x-user-id |
no | Caller's Salesforce user id, for traceability. |
x-org-id |
no | Caller's Salesforce org id, for traceability. |
x-azure-endpoint |
Azure only | The Azure OpenAI resource endpoint, e.g. https://my-resource.openai.azure.com. |
x-azure-api-version |
no | Azure API version. Defaults to 2024-02-01. |
The body is passed to the vendor verbatim. Send exactly the shape that vendor's API expects, keyed by the model you name in the body.
| Vendor | Body shape | SDK call it maps to |
|---|---|---|
openai (default) |
OpenAI Chat Completions: { model, messages, ... } |
openai.chat.completions.create |
azure |
Same as OpenAI; model = your deployment name |
Azure OpenAI chat.completions.create |
gemini |
Gemini: { model, contents, config?, stream? } |
@google/genai models.generateContent |
claude |
Anthropic Messages: { model, max_tokens, messages, ... } |
anthropic.messages.create |
x-ai-vendor is omitted.x-azure-endpoint; model in the body is the Azure
deployment name, and the API version comes from x-azure-api-version (default
2024-02-01).@google/genai shape; send contents, not messages.Set stream: true in the body to stream the response as Server-Sent Events.
data: <json> lines and
terminated with data: [DONE].event: <type> + data: <json>) and
signals completion with a message_stop event (not [DONE]).Streaming also avoids gateway timeouts on long generations: the proxy opens the
stream and sends keep-alive comments (: ping) immediately, before the model
produces its first token. If the client disconnects mid-stream, the proxy
aborts the upstream request.
| Status + body | Cause | Fix |
|---|---|---|
401 { "error": "Missing x-api-key header" } |
No x-api-key. |
Send the encrypted vendor key. |
401 { "error": "Invalid x-api-key header" } |
The key is not a valid encrypted vendor key. | Send the encrypted key produced by your 3B configuration. |
400 { "error": "Unsupported x-ai-vendor [x]. Supported: openai, azure, gemini, claude" } |
Unknown vendor value. | Use one of the four supported vendors. |
400 { "error": "Missing x-azure-endpoint header required for Azure OpenAI" } |
Azure vendor without the endpoint header. | Add x-azure-endpoint. |
Vendor error passed through (e.g. 401, 429, 400) |
The vendor rejected the request (bad key, rate limit, malformed body). | The proxy forwards the vendor's status and body. Fix per the vendor's message. |
SSE event: error frame mid-stream |
The upstream failed after streaming began (headers already sent). | Inspect the error payload in the final SSE event and retry. |