From f9c170426ac3c637637079379002bc06f0949c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Hedenstro=CC=88m?= <erik@hedenstroem.com> Date: Sat, 2 Mar 2024 11:15:57 +0100 Subject: [PATCH] Only set Helicone auth when talking to their API --- README.md | 7 +++++++ src/index.ts | 9 ++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b1f0f85 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Helicone Proxy Service + +This project provides a proxy service designed to forward requests to either the Helicone API or the OpenAI API based on the request characteristics and the provided authorization tokens. + +## Usage + +To use this proxy replace `https://api.openai.com/v1` with `https://worker.hedenstroem.com/helicone-proxy/v1` when configuring the OpenAI Base URL. diff --git a/src/index.ts b/src/index.ts index b18da2a..2abb5d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,13 +38,12 @@ export default { // Add your custom header to the request modifiedRequest.headers.set("Host", url.hostname); - modifiedRequest.headers.set("Helicone-Auth", "Bearer " + env.HELICONE_KEY); - - // Make the fetch request with the modified request - const response = await fetch(modifiedRequest); + if (url.hostname === "oai.hconeai.com") { + modifiedRequest.headers.set("Helicone-Auth", "Bearer " + env.HELICONE_KEY); + } // Return the response from the target server - return response; + return fetch(modifiedRequest); }, }; -- GitLab