OpenAI ChatGPT API is released - One of the most anticipat APIs ever

A guide to how you can get started using OpenAI ChatGPT API and how it can benefit you by providing some real examples.

· 7 min read
Get amazed by ChatGPT API

OpenAI's ChatGPT API is a state-of-the-art artificial intelligence platform. That managed to become the fastest growing app in history when it reached one hundred million users in only two months.

It enables the usage of natural language processing capabilities to everyone, not only tech geeks. Developers, content creators, influencers, businesses, and organizations are only some examples of groups that already are using ChatGPT a lot.

One thing that amaze people is how it manage to offer such a broad range of features, including text generation, question-answering, translation, code generation, and summarization.

In this article, we'll explore how you can take the next step. That is how to get started using OpenAI ChatGPT API and how it can benefit you.

📖
Make sure to download some of my best prompts in a PDF for free! Hint: You'll find the link somewhere in this post. :-)

How-to sign-Up to be able to use the API

To get started with OpenAI ChatGPT API, you first need to sign up for an account. The sign-up process is simple and straightforward, and you should be able to use the API in just a few minutes.

Here are the steps to get yourself an account:

  1. Go to the OpenAI website and click on "Get Started" in the top right corner of the page.
  2. Choose the API plan that best suits your needs. OpenAI offers several plans, including the Basic plan, which provides access to the GPT-3 model with a limited number of requests per month, and the Pro plan, which provides higher request limits and access to additional models.
  3. Enter your contact and payment information to create your account.
  4. Once you've signed up, you'll receive an API key that you can use to authenticate your requests. Remember to keep the API key safe and secure!

Exactly what is an API?

If you're completely new to all of this and feel uncertain what an API is, then I suggest you read some basic tutorials. By doing so you will benefit more from this article. I promise. If you're already familiar with what an API is and how to use one, jump to the next section.

Introduction to APIs, a curated list with great articles:

Regarding the last link to Postman. Postman is the most famous tool to test and / or work with APIs. It's a tool that can be used to consume an API, plus a lot of additional things. Postman is a tool that has been around for a long time.

Another tool worth mentioning, is Insomnia.

Best Practices for Using OpenAI ChatGPT API

Some things to remember to get the most out of using this API,

  1. Define your use case and goals upfront to optimize the API for your needs.
  2. Start with small requests to test and identify any issues early on.
  3. Optimize your inputs by providing clear and relevant prompts and avoiding ambiguity and noise.
  4. Utilize the API's customization options to fine-tune its behavior to your needs.
  5. Monitor and improve conversation quality by analyzing feedback and using metrics such as perplexity and BLEU score.

Keep these things in mind as you learn more about how to optimize how you use the API. The more time you spend on various optimizations the more impressive responses you'll get.

Finally, make sure to read OpenAIs Privacy policy as well as their Terms of use.

Basic examples to get you started using ChatGPT API

Bellow you'll find some basic examples to help you get started with ChatGPTs API. Feel free to either follow my examples or to produce your own.

My hope is that you'll see how easy it is to use the API, even for someone that isn't a developer.

For reference, look at the official documentation:

Chat completion - OpenAI API Documentation

Some good things to know before my basic examples. The chatgpt model that is used in all examples is, gpt-3.5-turbo. Also, I'll use Insomnia as I mention in the previous section. Another way to test ChatGPT API is to use OpenAIs new playground for ChatGPT. The final thing two things is first, an API key and secondly the API endpoint (URL to the API), https://api.openai.com/v1/chat/completions

1. Make the API generate some text based on your input

One of the most powerful features of OpenAI ChatGPT API is its ability to generate human-like text. It's very versatile and can be used for a lot of things. It all depends on the prompt. Some of the type of content that can be generated are articles, stories, poetry, factual, funny stories and much more.

Tell ChatGPT to tell a funny joke

As you see, to make a request you send (POST) data using JSON. You'll find a full explanation at OpenAIs documentation. The two JSON properties I send is model and messages. Messages is an array of JSON objects. Each object contains two properties, role (look at the third example to read more about role) and content.

2. Ask a question and receive an informative answer.

curl https://api.openai.com/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{
  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "Tell me about the pricing for using ChatGPT API"}]
}'

The answer I got was more or less, "As an AI language model, I do not have access to the exact pricing for ChatGPT API.". Mostly because my question was very vague. A good rule is, ask extremely specific questions or write detailed instructions and you will get much better response from the API.

3. Use ChatGPT as your personal translator.

A good use-case is to create your own translator. I think it's impressive how ChatGPT model is at both understanding and responding in any specific language.

An example to show a way to control both the length of the response but also the language used by ChatGPT:

messages=[
        {"role": "system", "content": "You are only allowed to
speak Swedish and your answers is as short as possible!"}, {"role": "user", "content": "Hello!"}, {"role": "assistant", "content": "Hej"}, {"role": "user", "content": "How many states are there in USA?"}

First, I give the instructions to the bot to only use Swedish and to provide answers that's as short as possible. To reinforce this behaviour, I wrote a basic example. Doing so can help the bot to understand how you'd like it to behave. Finally, I asked, in English, how many states there are in the US. The answer? "51."

An example of ChatGPT API and how to use roles

4. Customize the tone of the voice ChatGPT use.

This feature is useful for those who want to create a personalized experience for their users, or for businesses that want to tailor their chatbot's tone to their brand identity.

To accomplish this, users can utilize the ChatGPT API's "personality" feature. This feature allows users to define the tone and style of the chatbot's responses. Users can create custom personalities by providing samples of text that reflect the desired tone or instruct the bot to use any specific tone.

For example, a company that sells luxury goods may want their chatbot to have a formal and sophisticated tone to reflect their brand identity. On the other hand, a bot for children should use text that's easy to read and suitable for the purpose.

In summary, the fact that ChatGPT can adjust its "personality" allows users to customize the tone of the voice used in conversations, making ChatGPT useful for any audience.

4a. An example where ChatGPT pretends to be Albert Einstein,

ChatGPT use the tone of voice as Albert Einstein

4b. The same example except that ChatGPT pretends to be Yoda from Star Wars,

ChatGPT pretends to be Yoda from Star Wars

As you see, the question is identical, "What is the relativity theory?". But in the first example the answer could be like how AI-bert Einstein would have answered. In the second example, the answer is spot-on for the one and only, Yoda.

Yodapp and AI-bert Einstein talking about AI
"When AI becomes too powerful, worried about the future, you will be. But fear not, Al-bert Einstein here is. Great mind, he has. Hmm." - Yoda, 2023

Privacy concerns and security when using any AI tool

I think it should be obvious for anyone that either use ChatGPT on OpenAIs website or the API.

Remember to never share sensitive information like company secrets, passwords, or confidential information through the ChatGPT API (or the web app).

It's important to only share appropriate information for the context, like general product or service information. Also, make sure that any shared information complies with relevant laws and regulations. GDPR is a relevant example for me as a Swede.

The ChatGPT API is a powerful AI that can assist most people in one way or another.

However, like all online services, we need to be careful with what we choose to share to protect our data and privacy.

At the same time, some reactions I've seen, like companies, universities and schools that ban the use och ChatGPT is to me ridiculous. For many reasons.

  1. AI is here to stay, it's better to learn how to use it responsible.
  2. To ban the usage of ChatGPT but to allow employees to use smart phones with all kinds of apps is "weird".
  3. IT security is an important topic however I don't think ChatGPT is anywhere near the top 100 of my concerns.

Conclusions

The release of this API as well as the Whisper API (I will write a separate blog post about that) will have an enormous impact on many levels.