Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Artificial Intelligence

How to Setup OpenAI Reverse Proxy A Step-by-Step Guide

by Cloudbooklet
3 months ago
in Artificial Intelligence, Deep Learning
How To Setup Openai Reverse Proxy
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

In this tutorial, we will guide you through the process of configuring the OpenAI Reverse Proxy. The OpenAI Reverse Proxy allows you to securely integrate OpenAI API calls into your applications while maintaining control over the requests and responses. We will cover the necessary steps to set up and configure the reverse proxy effectively. Here […]

ADVERTISEMENT

In this tutorial, we will guide you through the process of configuring the OpenAI Reverse Proxy. The OpenAI Reverse Proxy allows you to securely integrate OpenAI API calls into your applications while maintaining control over the requests and responses. We will cover the necessary steps to set up and configure the reverse proxy effectively.

Here we will use a simple Node.js script for reverse proxy and deploy it in Hugging Face. We can also deploy it in our local computer manually with Node.js. But we are using Hugging Face, so that we can get the OpenAI Reverse Proxy URL. We can then use that API url on Janitor AI API or other services.

Table of Contents

  1. Create a Hugging Face Space
  2. Create Dockerfile
  3. Configure OpenAI API Secret
  4. Create Node.js file
  5. Check OpenAI Reverse Proxy Deployment
  6. Get your OpenAI Reverse Proxy URL
  7. Errors and Troubleshooting – API connection
  8. Conclusion

Also check: How to setup OpenAI Reverse Proxy with Nginx

ADVERTISEMENT

Create a Hugging Face Space

Login to your Hugging Face account, click on your profile icon on the right and click New Space.

You might also like

Chatgpt To Translate

How to Use ChatGPT to Translate Your Website or Blog

1 day ago
Fantasy Minecraft Servers

5 Best Fantasy Minecraft Servers in 2023

1 day ago
Openai Reverse Proxy Setup

Space Name: Enter the name for your space (openai-reverse-proxy).

Select Space SDK: Docker (We will use Docker to deploy).

ADVERTISEMENT

Choose Docker Template: Blank

Everything else can be default.

ADVERTISEMENT

Click Create Space.

Now a new machine with 2vCPU 16GB RAM will get provisioned for free.

ADVERTISEMENT

Create Dockerfile

Once you have created your space, you will be redirected to the App page. This page contains all details about your deployment.

Scroll a little below to see where it says “(Hint: Create the Dockerfile file right in your browser alternatively)”

ADVERTISEMENT
Openai Reverse Proxy Dockerfile

Click Create to add our Dockerfile configurations.

Copy the below code and add it to the Edit section input box.

FROM node:18

WORKDIR /app

RUN npm install express express-http-proxy

COPY . .

EXPOSE 7860

CMD [ "node", "server.js" ]

The above configuration configures a Debian 11 machine with Node.js 18. Then installs the required packages and deploys the application to run on port 7860.

Openai Reverse Proxy Dockerfile

Click Commit new file to main.

This will create a new Dockerfile inside your space.

Configure OpenAI API Secret

Now go to your space settings and scroll down to find Repository secrets.

Openai Api Secret

Click New Secret.

In the popup box, enter the following.

Name: OPENAI_KEY

Secret value: Your API Key from OpenAI

Openai Api As Secret Key

Click Add new secret.

Now you have added your OpenAI API key as a secret.

Create Node.js file

Now you need to create a server.js file with the reverse proxy configurations that can be used with your OpenAI API key.

Go to Files in your space.

Click Add file and then click Create a new file.

Name your file: server.js

Copy the below in your Edit section.

const express = require('express');
const proxy = require('express-http-proxy');
const app = express();
const targetUrl = 'https://api.openai.com';
const openaiKey = process.env.OPENAI_KEY
const port = 7860;
const baseUrl = getExternalUrl(process.env.SPACE_ID);

app.use('/api', proxy(targetUrl, {
  proxyReqOptDecorator: (proxyReqOpts, srcReq) => {
    // Modify the request headers if necessary
    proxyReqOpts.headers['Authorization'] = 'Bearer '+openaiKey;
    return proxyReqOpts;
  },
}));

app.get("/", (req, res) => {
  res.send(`This is your OpenAI Reverse Proxy URL: ${baseUrl}`);
});

function getExternalUrl(spaceId) {
  try {
    const [username, spacename] = spaceId.split("/");
    return `https://${username}-${spacename.replace(/_/g, "-")}.hf.space/api/v1`;
  } catch (e) {
    return "";
  }
}

app.listen(port, () => {
  console.log(`Reverse proxy server running on ${baseUrl}`);
});

Click Commit new file to main.

Now a server.js file will get created in your space.

Check OpenAI Reverse Proxy Deployment

Now you can go to your App page and see the deployment status. You will see something similar to the one below.

Openai Reverse Proxy Url

You can copy the url and safely close it.

If you check the URL in your browser you will see this output on your screen, which means reverse proxy API is working fine. The error is shown because you haven’t passed any parameters in your API url.

{
  “error”: {
    “message”: “Invalid URL (GET /)”,
    “type”: “invalid_request_error”,
    “param”: null,
    “code”: null
  }
}

Get your OpenAI Reverse Proxy URL

You can get your reverse proxy url of your deployment from your log or you can generate using the below method.

Syntax: https://<username>-<spacename>.hf.space/api/v1

Reverse Proxy Url

In this case my reverse proxy url is https://cloudbooklet-reverse-proxy.hf.space/api/v1

You can use the URL as the OpenAI Reverse Proxy URL of your applications.

Also read: How to Configure OpenAI Reverse Proxy in Janitor AI API

Errors and Troubleshooting – API connection

You may face some errors while using the Reverse proxy URL or API key in Janitor AI or Venus AI or some other platforms. Please check the below article to troubleshoot your errors.

Janitor AI not working: Errors and Solutions

Conclusion

Now you have learned how to setup and configure OpenAI reverse proxy on Hugging Face with Debian 11, Docker and Node.js.

Tags: ChatGPTDebianDockerNode.js
Share127Tweet79SendShare
Cloudbooklet

Cloudbooklet

Comments 36

  1. Avatar Of Alex Alex says:
    5 days ago

    Still says:
    insufficient_quota – You exceeded your current quota, please check your plan and billing details.

    Reply
Next

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Ai Statistics And Trends

AI Statistics and Trends: What You Need to Know in 2023

1 day ago
Block Youtube Ads

How to Block YouTube Ads on Android TV in 2023 (6 Easy Methods)

1 day ago
Wix Ai

Create a Professional Website with Wix AI Website Builder

2 days ago
Ai Song Generator

10 Best AI Song Generator in 2023 (Free and Paid)

2 days ago

Follow Us

Trending Articles

Minecraft Server Hosting

10 Best Minecraft Server Hosting Providers in 2023

September 18, 2023

Create High Quality AI Cover Song with Covers AI

10 Best AI Prompts for Writers to Improve Website SEO

Top 7 Free Dating Sites for Men in 2023

Microsoft Editor vs Grammarly: Which is the Best Grammar Checker?

7 Best AI Girl Generators for Creating Realistic and Beautiful AI Girls

Popular Articles

Who Unfollowed You On Instagram

How to Find Who Unfollowed You on Instagram

September 11, 2023

7 Best AI Content Detectors to Check Plagiarism

Remodeled AI: How to Transform Your Home with AI Interior Design

10 Best AI Summarizer Tools in 2023: A Review and Comparison

Microsoft Designer: AI Design Tool Now Available in Edge

12 Best AI Interior Design Platforms for 2023 [Free and Paid]

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.