Warning
AI Proxy has been shut down in favor of AI Pipe
This is an authorizing proxy for LLMs.
Log in at https://aiproxy.sanand.workers.dev/ with your IITM email ID to get your AIPROXY_TOKEN.
Then, instead of sending an API request to https://api.openai.com/:
- Replace
https://api.openai.com/withhttps://aiproxy.sanand.workers.dev/openai/ - Replace the OPENAI_API_KEY with the AIPROXY_TOKEN
For example:
curl -X POST http://aiproxy.sanand.workers.dev/openai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AIPROXY_TOKEN" \
-d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "What is 2 + 2"}]}'
curl -X POST http://aiproxy.sanand.workers.dev/openai/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AIPROXY_TOKEN" \
-d '{"model": "text-embedding-3-small", "input": ["king", "queen"]}'AI Proxy only supports these endpoints and models:
GET https://aiproxy.sanand.workers.dev/openai/v1/modelsPOST https://aiproxy.sanand.workers.dev/openai/v1/embeddingsmodel: text-embedding-3-small
POST https://aiproxy.sanand.workers.dev/openai/v1/chat/completionsmodel: gpt-4o-mini
It returns a set of additional headers:
cost: Cost of this request in USDmonthlyCost: Total costs (in USD) of requests used this month. Monthly limit is $0.5 (resets at midnight UTC on the first of the next month).monthlyRequests: Total requests made this month.
MongoDB setup
- Log into https://cloud.mongodb.com/ as [email protected]
- Under Network Access, add CloudFlare IP ranges
- Create a cluster called
iitm-tds - Enable Data API
App setup
- Log into https://dash.cloudflare.com/ as [email protected]
- Create a worker called
aiproxydeployed at https://aiproxy.sanand.workers.dev - Clone this repository
- Run
npm installto install dependencies - Run
npm run lintto validate code - Run
wrangler secret put <key>also add them to.dev.varsasKEY=value:AIPROXY_TOKEN_SECRET: Generated viacrypto.randomBytes(32).toString('base64url')OPENAI_API_KEY: Via OpenAI API KeysMONGODB_APP_ID: Via MongoDB > Data API > App Services > (App) > App IDMONGODB_API_KEY: Via MongoDB > Data API > Users > Create API Key
- Run
npm run deployto deploy on Cloudflare
To create an API token for an emailId, run:
secret = new TextEncoder().encode(AIPROXY_TOKEN_SECRET);
token = await new jose.SignJWT({ email: emailId }).setProtectedHeader({ alg: "HS256" }).sign(secret);Creates an authentication token for IITM users.
Query Parameters:
credential: Google OAuth credential token
Returns:
{token, email}on success{error}on failure
Returns usage statistics for users.
Query Parameters:
skip: Number of records to skip (default: 0)limit: Maximum records to return (default: 1000)month: Filter by month (YYYY-MM format)email: Filter by user emailsort: Field to sort by (descending order)
Returns list of available models.
Proxies chat completion requests.
Request Body:
model: Only supports "gpt-4o-mini"messages: Array of chat messagesstream: Not supported
Proxies embedding requests.
Request Body:
model: Only supports "text-embedding-3-small"input: Text to embed
All API responses include:
cost: Cost of current request in USDmonthlyCost: Total costs for current monthmonthlyRequests: Total requests for current month
- Monthly cost limit: $0.5 per user
- Costs per request:
- Embeddings: $0.02 per million tokens
- Chat completions: $0.003 per 1K prompt tokens, $0.006 per 1K completion tokens