SDK Integration
Drop-in helper that routes Anthropic and OpenAI SDK clients through Proxiq with a single line change. All security policies, DLP, caching, and routing apply automatically.
Table of contents
- Install
- Anthropic
- OpenAI
- Custom proxy URL
- Pass a token
- Helper functions
- Bypass in test environments
- What happens to each request
Install
bun add @proxiq/sdk
# or
npm install @proxiq/sdk
Anthropic
import { relay } from '@proxiq/sdk';
import Anthropic from '@anthropic-ai/sdk';
// One line — all calls now route through Proxiq
const client = relay(new Anthropic());
const response = await client.messages.create({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello!' }],
});
OpenAI
import { relay } from '@proxiq/sdk';
import OpenAI from 'openai';
const client = relay(new OpenAI());
const response = await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: 'Hello!' }],
});
Custom proxy URL
import { relay } from '@proxiq/sdk';
import Anthropic from '@anthropic-ai/sdk';
// Point at a remote Proxiq instance
const client = relay(new Anthropic(), { url: 'https://proxiq.yourcompany.com' });
Or via environment variable — no code changes needed:
export PROXIQ_URL=https://proxiq.yourcompany.com
Pass a token
If your Proxiq instance has auth.required: true, include the token in your SDK client:
import { relay } from '@proxiq/sdk';
import Anthropic from '@anthropic-ai/sdk';
const client = relay(new Anthropic({ apiKey: process.env.PROXIQ_TOKEN }));
The token is passed as the Bearer header — Proxiq resolves the upstream API key from the token record automatically. Your app never needs to hold the upstream API key directly.
Helper functions
import { getProxiqBaseUrl, isProxiqEnabled } from '@proxiq/sdk';
// Returns PROXIQ_URL env var or http://127.0.0.1:3099
const baseUrl = getProxiqBaseUrl();
// Returns false when PROXIQ_ENABLED=false
const enabled = isProxiqEnabled();
Bypass in test environments
export PROXIQ_ENABLED=false
When false, relay(client) returns the original client unchanged — no proxy routing, no DLP, no caching. Useful in CI or unit tests where you want direct API calls.
What happens to each request
When your app calls the relayed client, Proxiq:
- Resolves your token and loads the assigned security policy
- Scans message content against DLP patterns (block / redact / log)
- Checks the exact cache — returns instantly if matched
- Checks the semantic cache — returns if cosine similarity ≥ 0.94
- Routes to the appropriate model tier (if routing enabled)
- Forwards to the upstream provider
- Logs the request and any security events
- Returns the response (with output filter applied if configured)
Your application code sees a standard Anthropic or OpenAI SDK response — nothing changes from the client’s perspective.