From 276aa4fb291ba78da135ff01f7ba28759459447f Mon Sep 17 00:00:00 2001 From: Praveen Thirumurugan Date: Wed, 24 Dec 2025 16:33:54 +0530 Subject: [PATCH] Enhance logging and update README for SSRF warning - Updated console log messages in cost.ts and proxy.ts for clarity and consistency. - Added important SSRF warning in README.md regarding localhost access issues with certain clients, along with solutions using external proxy services. --- README.md | 25 +++++++++++++++++++++---- cost.ts | 2 +- proxy.ts | 7 ++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 16981c6..b0b654c 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,9 @@ OpenProxy uses path prefixes for clean provider detection: | `/openai/*` | `OPENAI_UPSTREAM_URL/*` | `Authorization: Bearer ` | | `/anthropic/*` | `ANTHROPIC_UPSTREAM_URL/*` | `x-api-key: ` or `Authorization: Bearer ` | +### SSRF Warning [Important] + +Some clients (e.g. Cursor) may block access to `localhost` or `127.0.0.1` URLs. If you encounter this issue, you can use an external proxy service like `ngrok` to open up your `localhost:3007` port to a public domain. This will enable you to use OpenProxy with such services. ### PostgreSQL Logging @@ -96,12 +99,26 @@ For example, to use Z.AI or other Anthropic-compatible providers with Claude Cod export ANTHROPIC_UPSTREAM_URL="https://api.z.ai/api/anthropic" export DATABASE_URL="postgresql://user:password@localhost:5432/database_name" pnpm dev - -# Configure Claude Code to use: -# API Base URL: http://localhost:3007/anthropic ``` -### Using with OpenAI-compatible clients +Configure Claude Code to use the following URL: `http://localhost:3007/anthropic` + +### Using with Cursor + +For example, to use Z.AI or other Anthropic-compatible providers with Cursor: + +```bash +export ANTHROPIC_UPSTREAM_URL="https://api.z.ai/api/anthropic" +export DATABASE_URL="postgresql://user:password@localhost:5432/database_name" +pnpm dev +``` + +> Cursor blocks access to `localhost` or `127.0.0.1` URLs by default. You can use an external proxy service like `ngrok` to open up your `localhost:3007` port to a public domain. Refer to the [SSRF Warning](#ssrf-warning-important) for more details. + +Configure Cursor to use the following URL for OpenAI API requests: `http://public-domain.ngrok-free.app/openai` +Configure Cursor to use the following URL for Anthropic API requests: `http://public-domain.ngrok-free.app/anthropic` + +### Using with other OpenAI-compatible clients For example, to use Z.AI or other OpenAI-compatible providers with OpenAI-compatible clients: diff --git a/cost.ts b/cost.ts index e230ded..4a509ba 100644 --- a/cost.ts +++ b/cost.ts @@ -133,7 +133,7 @@ export async function loadHeliconeCosts(): Promise { } heliconeCostsLoaded = true; - console.log(`\x1b[36m 🌎 Loaded ${data.metadata.total_models} model costs from Helicone\x1b[0m`); + console.log(`\x1b[96m 🌎 Loaded ${data.metadata.total_models} model costs from Helicone API\x1b[0m`); } catch (error) { console.warn(`\x1b[33m ⚠️ Failed to load Helicone costs: ${error instanceof Error ? error.message : error}\x1b[0m`); } diff --git a/proxy.ts b/proxy.ts index dc31b1a..b314519 100644 --- a/proxy.ts +++ b/proxy.ts @@ -281,6 +281,7 @@ async function persistDatabaseRecord(data: Record) { */ const server = http.createServer(async (req: IncomingMessage, res: ServerResponse) => { const startTime = Date.now(); + console.log(`[\x1b[30m${new Date().toISOString()}\x1b[0m] \x1b[93m${req.method} \x1b[0m\x1b[94m${req.url}\x1b[0m`); try { const url = new URL(req.url || "/", `http://${req.headers.host}`); const path = url.pathname; @@ -483,10 +484,10 @@ async function startServer() { await loadHeliconeCosts(); server.listen(PORT, () => { - console.log(`\n\x1b[32mOpenProxy upstream connections activated ⟣⟢\x1b[0m\n`); + console.log(`\n\x1b[32mOpenProxy ready... ⟣⟢\x1b[0m\n`); - if (OPENAI_UPSTREAM_URL) console.log(`\x1b[34m 📡 http://localhost:${PORT}/openai/* → ${OPENAI_UPSTREAM_URL}\x1b[0m`); - if (ANTHROPIC_UPSTREAM_URL) console.log(`\x1b[34m 📡 http://localhost:${PORT}/anthropic/* → ${ANTHROPIC_UPSTREAM_URL}\x1b[0m\n`); + if (OPENAI_UPSTREAM_URL) console.log(`\x1b[94m 📡 http://localhost:${PORT}/openai/* → ${OPENAI_UPSTREAM_URL}\x1b[0m`); + if (ANTHROPIC_UPSTREAM_URL) console.log(`\x1b[94m 📡 http://localhost:${PORT}/anthropic/* → ${ANTHROPIC_UPSTREAM_URL}\x1b[0m\n`); }); }