What is OpenAI’s API? [+ How to Start Using It]

Download Now: How to Use an API
Jamie Oppel

Published:

With the recent surge in ChatGPT’s popularity, we’d be surprised if you haven’t at least heard of OpenAI, the company behind it.

a visual representation of open ai's API with graphics

Open AI is an artificial intelligence research and development company based in San Francisco, California. It develops powerful AI models that you can leverage through tools like ChatGPT, a large language model, and DALL-E, a text-to-image model.

Download our Free Ebook: How to Use an API

In this post, you’ll learn what you need to know to get started with OpenAI’s API and how to integrate its technology in your own programs. Let’s get started.

Table of Contents

What is OpenAI’s API?

OpenAI’s API enables users to leverage the power of their AI models, but what exactly does that mean? Put plainly, the API allows you to send requests to OpenAI’s models and receive information in return.

This is really the function of any API, but this article is specific to OpenAI’s REST API. The models that you can currently access with OpenAI’s API are GPT, DALL-E, and Whisper, a speech recognition model.

With the API, you can essentially merge OpenAI’s technology with your own application. If you’re using a product that incorporates generative AI language output, for example, there’s a good chance its accessing the OpenAI API. To that end, even HubSpot leverages OpenAI to power its own AI tools.

Benefits of OpenAI’s API

There are many benefits to using OpenAI’s API, including but not limited to powering AI chatbots, serving a wide range of customers without language limits, and leveraging continual updates and advances in the technology to “future-proof” your application.

AI Chatbots

Integrating OpenAI’s API into your chatbot provides automated support to customers and prospects, which increases efficiency and makes for a better user experience since communication is more human-like and personalized.

With AI-powered chatbots getting better by the day, it’s not far-fetched to think about using AI chatbots instead of needing true 24/7 live support from actual people. Sure, an AI chatbot won’t be quite as robust or versatile as a true expert in the field, but it can alleviate pressure from common problems.

Many IT issues are recurring, and many places even have copy-paste responses for the recurring issues. Why not cut the workload by having an AI automatically recognize when these canned responses should be used, and save the complex tasks for when AI reaches its limits?

Analysis

Open AI’s API can also be used for analysis on multiple levels. It could be something like data analysis in the context of user behavior in order to determine trends and make better recommendations to your customers. Or, the context can even be security-related, using that same behavioral analysis to detect suspicious activity and respond accordingly.

Whatever the purpose of the analysis, Open AI’s API can provide data-driven insights and automated responses in order to greatly improve the performance and effectiveness of your applications.

Bleeding Edge Technology

While there may not truly be such a thing as “future-proofing” in the world of technology, leveraging OpenAI gets pretty close. By incorporating OpenAI’s technology, you are ensuring that you benefit from any updates and advances in the technology.

OpenAI currently has a valuation around 27 to 29 billion US dollars, and over a billion users per month and is still growing rapidly. Considering that machine learning and AI are on the rise and don’t show any signs of stopping, it’s a safe bet that integrating OpenAI into your application will ensure you’re at the forefront of technological development and solutions for a while.

How to Use OpenAI’s API

Using OpenAI’s API is similar to using just about any other public API — you sign up, get an API key, and then use your key to make API calls to any of their models using HTTP requests.

I’ll walk you through the general process of sending an API call using their Postman, though I highly recommend you check out the official API Reference for all the details.

Getting Your API Key and Authentication

To get your API Key, go to platform.openai.com and create an account. Then, click on your account bubble near the top right of the page and select “View API keys” from the drop-down menu.

OpenAI account menu

Image Source

From there, click “Create new secret key” and create a new API key.

Clicking create new secret key to get an API key

Image Source

Name the key whatever you wish and it will give you a long string of numbers and characters.

Be sure to save this key in a secure place, and do not show it to anyone that you don’t want to have access to your account. Treat it like a very secure password! Considering that using their API costs money, you run the risk of someone draining your API credits or messing with your application altogether if they have your API key and you don’t realize it.

Making Requests

Now that you have your API key, open your preferred API client and make an authorization request in order to get your token. One of the reasons that I chose Postman is because of how easy it is to do authorization and modify your API calls, though you can use whatever tool you want.

For this example, open up Postman, create a new GET request, input the base URL https://api.openai.com/v1/models and click the “Authorization” tab. From here, simply copy and paste your API key into the API Key field, then save the resulting token to your environment and you can start making calls without having to repeat the process.

If you don’t want to use Postman’s authorization tab, simply insert an “Authorization” key in the headers with the value “Bearer” followed by a space and your API key.

Getting authorization using your API key in Postman

Image Source

Now that you’re authorized, you can start crafting your request. In an effort to keep things simple and digestible, I’ll start with a basic GET request to get a list of all available models.

Getting a list of the currently available models

Image Source

In order to get anything useful out of this, you are definitely going to need POST requests. Fortunately, that part is as easy as copying and pasting some JSON from their API documentation and tweaking it to your needs. Look below for an example using their chat completion AI.

Sending a POST request to the chat completion AI and getting a response

Image Source

alIf the above request and response look a bit like gibberish, that’s okay. In the above request, I told the system that it is to speak in “leet speak” and the user simply asked, “How are you?” In response, the assistant replied “H3ll0, h0w 4r3 y0u?”

Of course, we’re scratching the surface of the API’s power, but now you have the basic idea of how to send off a request.

Best Practices for OpenAI’s API

Now you know the basics of using OpenAI’s API. But you don’t just want to know how to use it — you want to use it intelligently. Below are three tips that can help you become a power user.

Use the Playground

The Playground is a tool from OpenAI that you can use to learn how to construct prompts, so that you can get comfortable using querying the model and learning how the API works.

Visual information is largely easier to work with for us. So, rather than using a pure text interface, you may have an easier time setting things up using the Playground’s graphical user interface, then clicking the “View code” button near the top right and simply copy-pasting the code into your program.

Something like Postman is also suited for setting up requests in a visual way, but the OpenAI playground will be without a doubt the fastest and most effective way of setting requests up.

 The ‘view code’ feature in OpenAI’s Playground

Image Source

Check out the Examples

Whatever issue you are trying to solve, chances are someone else has already attempted it, or something similar to it.

So, in an effort to reduce redundancy and attempts at reinventing the wheel, head to the examples page and check out some examples before starting from scratch.

There are a lot of interesting projects here, and many of these can be adapted to suit your personal needs. My personal favorite is Marv the sarcastic chat bot — if a chatbot talked to me like that, I would definitely come back for more.

Read the Documentation

This is another tip that might seem obvious at a glance. However, I am still mentioning it because there is a difference between using the API reference, and the general documentation.

It can be extremely tempting to just jump straight into the reference material and start working with things, especially if you are an experienced API user. However, reading the general documentation can provide a lot of context and best practices that you simply won’t find in the reference material.

In a way, this “Best Practice” tip is like a nesting doll of other best practices. Don’t believe me? Check out their GPT best practices section, it’s a treasure trove of information and strategies to consider when crafting your responses.

Learn the API behind countless AI-powered applications.

In this article, you learned what Open AI’s API is, the benefits of using it, how to get it up and running, as well as some best practices. You also got shown a few tools to better craft your requests, and a few points of consideration before doing so.

Now that you have everything you need to start working with the OpenAI API, you start building that amazing web app of your dreams. Or, you can just build another sarcastic chatbot that can roast me into oblivion when I merely ask for the time — your choice.

api

Related Articles

We're committed to your privacy. HubSpot uses the information you provide to us to contact you about our relevant content, products, and services. You may unsubscribe from these communications at any time. For more information, check out our Privacy Policy.

Everything you need to know about the history and use of APIs.

CMS Hub is flexible for marketers, powerful for developers, and gives customers a personalized, secure experience

START FREE OR GET A DEMO