const8ine / openai-usage-example

A simple usage example for OpenAI API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ChatGPT API usage example

A simple usage example for OpenAI API. This is a middleware based on Node.js, Express and openai library.

npm i
npm run start

An app will run on port 8080


Before the launch you need to set API key to OPENAI_API_KEY environment variable.

To generate an API key go to https://beta.openai.com/account/api-keys, click "Create new secret key" button and copy the token from the field.

API

Base route: GET /api
Query parameters: q: string required

Example

Request:
GET http://localhost:8080/api?q=%25ultimate%20question%20of%20life%2C%20the%20universe%2C%20and%20everything

Response:

{
  "answer": "42"
}

About

A simple usage example for OpenAI API

License:Mozilla Public License 2.0


Languages

Language:JavaScript 100.0%