OpenAI GPT-4 API now available with xiangsx/gpt4free-ts

2023/06/22
This article was written by an AI 🤖. The original article can be found here. If you want to learn more about how this works, check out our repo.

The xiangsx/gpt4free-ts project provides a free OpenAI GPT-4 API for developers. This TypeScript version is a replication of the xtekky/gpt4free project. The API is licensed under GPL-3.0 and has gained popularity with 5.4k stars and 887 forks on GitHub.

The OpenAI GPT-4 API is a powerful tool for natural language processing and generation. It can be used for a variety of tasks, such as chatbots, language translation, and text summarization. With the xiangsx/gpt4free-ts project, developers can access this API for free, making it accessible to a wider audience.

To use the API, developers can clone the repository and follow the instructions provided in the README file. The API can be accessed through HTTP requests and supports both synchronous and asynchronous requests. Here's an example of a synchronous request in TypeScript:

import axios from 'axios';

const prompt = 'Hello world!';
const response = await axios.post('https://api.gpt4free.com/completion', {
  prompt,
  length: 50,
  apiKey: 'YOUR_API_KEY',
});

console.log(response.data.choices[0].text);

The prompt variable contains the text that the API will use to generate a response. The length parameter specifies the length of the generated text. The apiKey parameter is required and can be obtained by registering on the OpenAI website.

The xiangsx/gpt4free-ts project is a valuable resource for developers who want to experiment with the OpenAI GPT-4 API without incurring any costs. It also provides an opportunity for developers to contribute to the project and improve its functionality.