How to use ChatGPT API to make your own apps

Dell laptop with ChatGPT window open
(Image credit: Future / OpenAI / Dell)

ChatGPT has taken the internet by storm as more and more people discover what the artificial intelligence is capable of, and find new ways to push the boundaries with cleverly worded commands. The AI can be used by anyone for fun or more serious pursuits, and developers have the option of using the ChatGPT API to add it into their own creations.

The prospect of integrating ChatGPT into an app is an enticing one. The artificial intelligence is a trusted and evolving technology, and using the API to harness its power means that developers are able to add features to their apps that would either not be possible otherwise, or would take years of expensive work.

Just as you can use the ChatGPT website to have your questions answered by AI, so you can bring the same capabilities to your apps, websites and services for customers and users to take advantage of. Let's take a look at how to get started with the API.

If you want to explore more about programming and coding, then check out our buying guides on the best laptop for programming, the best monitor for programming and the best text editors.

Steps for how to use ChatGPT API

  • Sign up for an OpenAI account
  • Generate a secret key
  • Chosen an API model and pay for tokens
  • Call the API from your code

Tools and Requirements

  • OpenAI account
  • ChatGPT API key

Step by step guide

1. Generate your API

(Image: © Sofia Wyciślik-Wilson)

The first thing to do, assuming you already have an OpenAI account in order to access ChatGPT, is to get hold of your unique API key. Once you are logged in, click the Personal link to the upper right-hand corner of the page and select View API keys - or you can click here. You can then click the Create new secret key button, enter a suitable name, click Create secret key, and an API key will be generated for you.

2. Copy and save your key

(Image: © Sofia Wyciślik-Wilson)

Once your secret key has been created, you are given one - and only one - chance to view it. As the warning that appears points out, this is the time to save the key somewhere safe as there is no way to view it again in your OpenAI account. You can simply copy and paste the key into a document and then save it somewhere secure. When you've saved the key, click Done.

3. Free trial API usage

(Image: © Sofia Wyciślik-Wilson)

Although it is free to use ChatGPT, access to and use of the OpenAI API is something that you will need to pay for. When you sign up for your account, you are given some free credit that enable you to play around with the API a bit and try out different options before you start to pay. You can keep and eye on how much credit you have left and your overall API usage by heading to the Usage section of your account page.

4. API models

(Image: © Sofia Wyciślik-Wilson)

Referring the "the ChatGPT API" is a little misleading, as there is actually no such thing -- there is the OpenAI API, and there are various models available. Depending on your needs and budget, you can choose between GPT-3.5 and GPT-4 models, and within both of these there are numerous options to choose from. Each has different capabilities, different token limits (of which more in a moment), ad uses different training data. The code you use to call the API determine which model you use. You can read full details of the various models, their capabilities and limitations here.

5. Tokens and pricing

(Image: © Sofia Wyciślik-Wilson)

Interacting with the API and using it in your own applications uses tokens, and these cost money. A token is used to "pay" for input and output with the API - put another way, a query made with of the API must be paid for, as must the answer it provides. The token limits for different models restrict the length of queries made of the API (i.e. questions asked by a user) as well as the length of he responses it gives. Full details of the latest token pricing and models can be found here. It is also worth taking a look at the Rate limits section of your account page where you can check the rate limits on the requests you can make to different API models.

6. Take a look at example applications

(Image: © Sofia Wyciślik-Wilson)

You may well have an idea of what you would like to achieve with the API, and if this is the case you can dive right in and do so. But if you're looking for some inspiration, you can take a look at some example applications to see just what the API is capable of. Take a look at this page on the OpenAI website and you not only try out various applications, but also learn the API requests being used so you can replicate it yourself. This is a great way to learn the necessary coding.

7. Check the API documentation

(Image: © Sofia Wyciślik-Wilson)

The possibilities of what can be achieved with the ChatGPT API, and the number of potential usage scenarios, is colossal. Thankfully, OpenAI has put together some comprehensive documentation that serves as an incredibly useful guide when you're trying to work out how to do something, and need to tailor things to your situation and project. The API documentation is available here.

Final thoughts

The accessibility of the API opens up ChatGPT to anyone who has an idea and wants to make use of this powerful tool.  The possibilities for what can be achieved are wide-ranging and the accessibility of the API is hugely democratising and a great leveller. The technology has been embraced by lots of big companies, but it is available for anyone to use in the same way.

The fact that the ChatGPT API can be accessed in a number of ways – such as using Python or with JavaScript – opens up a lot of options when it comes to bolting the AI into new or existing projects. For anyone who has entertained the idea of adding a helpful chatbot to their site or service but believed it to be an unattainable dream, the API makes possible what was once thought impossible.

Sofia Elizabella Wyciślik-Wilson
Freelance writer

Sofia is a tech journalist who's been writing about software, hardware and the web for nearly 20 years – but still looks as youthful as ever! After years writing for magazines, her life moved online and remains fueled by technology, music and nature.

Having written for websites and magazines since 2000, producing a wide range of reviews, guides, tutorials, brochures, newsletters and more, she continues to write for diverse audiences, from computing newbies to advanced users and business clients. Always willing to try something new, she loves sharing new discoveries with others.

Sofia lives and breathes Windows, Android, iOS, macOS and just about anything with a power button, but her particular areas of interest include security, tweaking and privacy. Her other loves include walking, music, her two Malamutes and, of course, her wife and daughter.

You can find her on Twitter and Mastodon.