Top 5 Free OpenAI API Solutions: Unleash the Power of AI for Free

Jennie Lee
7 min readApr 4, 2024

--

Looking for a Postman alternative?

Try APIDog, the Most Customizable Postman Alternative, where you can connect to thousands of APIs right now!

Introducing Llama 2 API: Making OpenAI More Accessible on Cloudflare Workers AI

Introduction to Llama 2 API and its compatibility with OpenAI

As a software testing engineer, I am always on the lookout for new and innovative solutions that harness the power of AI. One platform that has caught my attention is OpenAI, with its state-of-the-art language models and natural language processing capabilities. I frequently use OpenAI’s API, especially ChatGPT, for various projects and testing scenarios. However, as much as I appreciate their offerings, I also believe in the power of open-source solutions. That’s why I am excited to introduce the Llama 2 API — an OpenAI-compatible API for Workers AI hosted by Cloudflare.

The author’s affinity for OpenAI and the need for open-source Generative AI

OpenAI has made significant contributions to the field of AI with its GPT models, allowing users to generate human-like text based on a given prompt. However, while OpenAI’s offerings are powerful, they are not accessible to everyone. The current pricing model might make it difficult for individuals or small businesses to access these advanced AI capabilities. This is where open-source solutions come in — they democratize access to AI and allow more people to benefit from the advancements in this field.

Overview of Cloudflare’s Workers AI platform and its beta offering

Cloudflare has always been at the forefront of providing innovative solutions for developers. Recently, they launched Workers AI, a platform that enables developers to run GPU-heavy AI tasks on Cloudflare’s global network. This platform comes with a beta offering that allows users to try out a limited set of AI models, with one model available for each general category of AI technology. It’s an exciting opportunity for developers to leverage Cloudflare’s infrastructure for AI tasks without the need for expensive hardware or complex setup.

OpenAI for Workers AI: Hosting Your Own OpenAI-Compatible API

The author’s solution: OpenAI for Workers AI

While Cloudflare’s Workers AI platform offers a handful of AI models, it might not cover every possible use case or cater to everyone’s specific requirements. That’s where OpenAI for Workers AI comes into play. It allows developers to host their own OpenAI-compatible API on Cloudflare Workers, expanding the possibilities of what they can achieve with OpenAI’s models.

Benefits of hosting your own OpenAI-compatible API on Cloudflare Workers

By hosting your own OpenAI-compatible API on Cloudflare Workers, you gain more control and flexibility over the AI models you use. You are not limited to the models provided by Cloudflare’s Workers AI platform but can access and deploy any model available within the OpenAI ecosystem. This opens up a world of possibilities for developers, allowing them to experiment with different models and find the best fit for their specific use cases.

Leveraging existing OpenAI SDKs and tooling for quick model usage and testing

One of the advantages of using OpenAI for Workers AI is that you can continue to leverage the existing OpenAI SDKs and tooling. This means that you don’t have to rewrite your code or learn new frameworks just to use your own OpenAI-compatible API. You can simply integrate your API with your existing codebase and start utilizing OpenAI’s models in no time. This saves you valuable development time and resources, enabling you to focus on your AI applications rather than the setup process.

Step-by-Step Guide: Setting Up OpenAI API on Cloudflare Workers

Cloning the repository and installing dependencies for OpenAI API

To set up your own OpenAI-compatible API on Cloudflare Workers, the first step is to clone the OpenAI for Workers AI repository. This repository contains all the necessary code and configuration files to get started. Once you have cloned the repository, navigate to the project folder and install the required dependencies using your preferred package manager. In this guide, we will use yarn as an example:

git clone https://github.com/cloudflare/llama-api.git
cd llama-api
yarn install

Deploying the API to your Cloudflare account using yarn commands

After installing the dependencies, you need to deploy the API to your Cloudflare account. This requires you to have a Cloudflare account and the necessary permissions to deploy code to Cloudflare Workers. Once you have authenticated your Cloudflare account, you can deploy the API using the following yarn command:

export CF_API_EMAIL=<YOUR_CLOUDFLARE_EMAIL>
export CF_API_KEY=<YOUR_CLOUDFLARE_API_KEY>
yarn deploy

This command will build and deploy the OpenAI-compatible API to your Cloudflare Workers account. It will give you a unique URL that you can use to access the API and make requests.

Usage example of the OpenAI API with curl to generate chat completions

With your API deployed, you can now use it to generate chat completions using OpenAI’s models. To demonstrate the usage, let’s generate a chat completion using curl. Replace <API_URL> with the URL given to you during the deployment process:

curl -X POST -H "Content-Type: application/json" -d '{
"model": "text-davinci-003",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
}' <API_URL>

This curl command sends a POST request to the OpenAI-compatible API with the necessary payload to generate a chat completion. The response will contain the generated chat response, which you can use in your application as needed.

Compromises and Limitations of the OpenAI API on Cloudflare Workers

Discussion on the compromises made in creating the API

While OpenAI for Workers AI offers several benefits and flexibility, it also comes with a few compromises. One of the main compromises is the inability to count tokens in the API. Token counting is crucial when using OpenAI’s models as it directly affects the cost and length of the generated text. This means that you will have to estimate the number of tokens in your requests to manage your usage effectively.

Challenges with token counting, limited model selection, stop tokens, and API key functionality

In addition to token counting, the OpenAI for Workers AI API has a limited model selection compared to OpenAI’s official API. This limitation means that not all models available in the OpenAI ecosystem can be used with this API. Additionally, there is currently no functional support for stop tokens in the API, which can make it challenging to control the length and coherence of the generated text. Finally, the API does not provide API key functionality, which may be a concern for users who rely on API keys for authentication and usage tracking.

Possibility of addressing these limitations in future updates

The compromises and limitations mentioned above are not permanent restrictions but rather areas of improvement for future updates. As the integration between OpenAI and Cloudflare Workers evolves, it is possible that these limitations will be addressed, providing users with a more seamless and comprehensive AI experience. Cloudflare and the open-source community are continually working on enhancing the Llama 2 API to make it even more accessible and user-friendly.

Exploring the Potential: Cloudflare’s Workers AI and OpenAI Integration

Highlighting the potential of Cloudflare’s Workers AI platform

The combination of Cloudflare’s Workers AI platform and OpenAI’s models opens up a realm of possibilities for developers. With the ability to run GPU-heavy AI tasks on Cloudflare’s global network, developers can leverage the scalability, performance, and security of Cloudflare to create powerful AI applications. This integration democratizes access to AI capabilities and eliminates the need for costly infrastructure investments.

Benefits of integrating OpenAI with Workers AI for GPU-heavy AI tasks

By integrating OpenAI with Workers AI, developers can harness the power of OpenAI’s models while offloading the heavy lifting to Cloudflare’s infrastructure. This is particularly beneficial for GPU-intensive tasks, as Cloudflare’s global network provides fast and reliable access to GPUs without the need for local hardware. Developers can focus on building their AI applications while Cloudflare handles the compute-intensive aspects.

The author’s optimism for the future of Cloudflare’s Workers AI and OpenAI integration

As an advocate for open-source solutions and accessible AI, I am optimistic about the future of Cloudflare’s Workers AI and the integration with OpenAI. With ongoing developments and improvements, this integration has the potential to revolutionize the way developers utilize AI capabilities. By making AI more accessible and open-source, we can unlock the power of AI for everyone and pave the way for innovative and transformative applications.

In conclusion, the Llama 2 API, an OpenAI-compatible API for Cloudflare Workers AI, provides an exciting opportunity for developers to host their own OpenAI-compatible API and leverage the power of OpenAI’s models. While there are some compromises and limitations at present, the potential for future updates and enhancements gives hope for a more versatile, efficient, and user-friendly integration between OpenAI and Cloudflare Workers.

Looking for a Postman alternative?

Try APIDog, the Most Customizable Postman Alternative, where you can connect to thousands of APIs right now!

--

--

Jennie Lee
Jennie Lee

Written by Jennie Lee

Software Testing Blogger, #API Testing

No responses yet