AiAyw

AiAyw

在这里,探讨最新的 Web3 技术和人工智能领域的前沿发展。

Deploy OpenAI-Key Balance Query Website with Cloudflare Workers

Preface#

Because I don't trust the Key API query websites online, I wanted to build a simple one myself. I found a query interface through an open-source project and had GPT-4 write the code for OpenAI-Key balance query (100% AI completed).

Deploying OpenAI-API-Key Details Query Using Cloudflare Workers
Due to limitations of the official OpenAI API, only the consumption information for the most recent month can be queried.

Deployment Tutorial#

Open-source link: https://github.com/Aiayw/OpenAI-APIKey-Query
Simply create a new project in Cloudflare Workers web version, and copy the apikey.js from this repository into the online editor and save to complete the deployment.

Web Preview#

Preview webpage: https://apikey.aiayw.workers.dev

image

Code Description#

This code is a web application with the following functionality:

  1. When a user visits the webpage of the application, a form page for querying API key information will be displayed.
  2. Users need to enter an OpenAI API key starting with "sk-" in the form and submit it for querying.
  3. After the user submits the form, the application will send a request to the OpenAI API using the provided API key to query account information and consumption details.
  4. If the request is successful, the application will display the returned account information and consumption details, including account name, card binding status, consumption amount in the past two months, monthly consumption hard limit, total credit limit of the account, and validity period of the gift quota.
  5. If the request fails, the application will display an error message.
  6. The application uses the Bootstrap framework and CSS styles to beautify the page.
  7. The application uses JavaScript and Fetch API to handle form submission and communicate with the backend API.
  8. The backend code uses Cloudflare Workers as a serverless function to handle requests.
  9. The backend will validate the validity of the API key, then send a request to the OpenAI API to get account and consumption information, and return it to the frontend.
  10. If an error occurs in the backend, an appropriate error message will be returned to the frontend.
  11. Both the frontend and backend of the application support displaying error messages in both Chinese and English.

Overall, this code implements a functionality to query OpenAI API key information, where users can obtain account information and consumption details by filling in the API key and submitting the form.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.