




















































Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!
This article is an excerpt from the book, Building AI Applications with ChatGPT APIs, by Martin Yanev. Master core data architecture design concepts and Azure Data & AI services to gain a cloud data and AI architect’s perspective to developing end-to-end solutions
In this article, we'll walk you through the essential steps to get started with ChatGPT, from creating your OpenAI account to accessing the ChatGPT API. Whether you're a seasoned developer or a curious beginner, you'll learn how to harness the capabilities of ChatGPT, understand tokens, and pricing, and explore its versatility in various NLP tasks. Get ready to unlock the potential of ChatGPT and embark on a journey of seamless communication with AI.
Before using ChatGPT or the ChatGPT API, you must create an account on the OpenAI website, which will give you access to all the tools that the company has developed. To do that, you can visit https://chat.openai.com, where you will be asked to either login or sign up for a new account, as shown in Figure 1.1:
OpenAI Welcome Window
Simply click the Sign up button and follow the prompts to access the registration window (see Figure 1.2). From there, you have the option to enter your email address and click Continue, or you can opt to register using your Google or Microsoft account. Once this step is complete, you can select a password and validate your email, just like with any other website registration process.
After completing the registration process, you can begin exploring ChatGPT’s full range of features. Simply click the Log in button depicted in Figure 1.1 and enter your credentials into the Log In window. Upon successfully logging in, you’ll gain full access to ChatGPT and all other OpenAI products. With this straightforward approach to access, you can seamlessly explore the full capabilities of ChatGPT and see firsthand why it’s become such a powerful tool for natural language processing tasks.
OpenAI Registration Window
Now we can explore the features and functionality of the ChatGPT web interface in greater detail. We’ll show you how to navigate the interface and make the most of its various options to get the best possible results from the AI model.
The ChatGPT web interface allows users to interact with the AI model. Once a user registers for the service and logs in, they can enter text prompts or questions into a chat window and receive responses from the model. You can ask ChatGPT anything using the Send a message… text field. The chat window also displays previous messages and prompts, allowing users to keep track of the conversation’s context, as shown in the below figure:
ChatGPT Following Conversational Context
In addition to that, ChatGPT allows users to easily record the history of their interactions with the model. Users’ chat logs are automatically saved, which can later be accessed from the left sidebar for reference or analysis. This feature is especially useful for researchers or individuals who want to keep track of their conversations with the model and evaluate its performance over time. The chat logs can also be used to train other models or compare the performance of different models. You are now able to distinguish and use the advancements of different ChatGPT models. You can also use ChatGPT from the web, including creating an account and generating API keys. The ChatGPT API is flexible, customizable, and can save developers time and resources, making it an ideal choice for chatbots, virtual assistants, and automated content generation. In the next section, you will learn how to access the ChatGPT API easily using Python.
The ChatGPT API is an application programming interface developed by OpenAI that allows developers to interact with Generative Pre-trained Transformer (GPT) models for natural language processing (NLP) tasks. This API provides an easy-to-use interface for generating text, completing prompts, answering questions, and carrying out other NLP tasks using state-of-the-art machine learning models.
The ChatGPT API is used for chatbots, virtual assistants, and automated content generation. It can also be used for language translation, sentiment analysis, and content classification. The API is flexible and customizable, allowing developers to fine-tune the model’s performance for their specific use case. Let’s now discover the process of obtaining an API key. This is the first step to accessing the ChatGPT API from your own applications.
To use the ChatGPT API, you will need to obtain an API key. This can be obtained from OpenAI. This key will allow you to authenticate your requests to the API and ensure that only authorized users can access your account.
To obtain an API key, you must access the OpenAI Platform at https://platform.openai. com using your ChatGPT credentials. The OpenAI Platform page provides a central hub for managing your OpenAI resources. Once you have signed up, you can navigate to the API access page: https:// platform.openai.com/account/api-keys. On the API access page, you can manage your API keys for the ChatGPT API and other OpenAI services. You can generate new API keys, view and edit the permissions associated with each key, and monitor your usage of the APIs. The page provides a clear overview of your API keys, including their names, types, and creation dates, and allows you to easily revoke or regenerate keys as needed.
Click on the +Create new secret key button and your API key will be created:
Creating an API Key
After creating your API key, you will only have one chance to copy it (see below figure). It’s important to keep your API key secure and confidential, as anyone who has access to your key could potentially access your account and use your resources. You should also be careful not to share your key with unauthorized users and avoid committing your key to public repositories or sharing it in plain text over insecure channels.
Saving an API Key
Copying and pasting the API key in our applications and scripts allows us to use the ChatGPT API. Now, let’s examine the ChatGPT tokens and their involvement in the OpenAI pricing model.
When working with ChatGPT APIs, it’s important to understand the concept of tokens. Tokens are the basic units of text used by models to process and understand the input and output text.
Tokens can be words or chunks of characters and are created by breaking down the text into smaller pieces. For instance, the word “hamburger” can be broken down into “ham,” “bur,” and “ger,” while a shorter word such as “pear” is a single token. Tokens can also start with whitespace, such as “ hello” or “ bye”.
The number of tokens used in an API request depends on the length of both the input and output text. As a rule of thumb, one token corresponds to approximately 4 characters or 0.75 words in English text. It’s important to note that the combined length of the text prompt and generated response must not exceed the maximum context length of the model. Table 1.1 shows the token limits of some of the popular ChatGPT models.
API model token limits
To learn more about how text is translated into tokens, you can check out OpenAI’s Tokenizer tool. The tokenizer tool is a helpful resource provided by OpenAI for understanding how text is translated into tokens. This tool breaks down text into individual tokens and displays their corresponding byte offsets, which can be useful for analyzing and understanding the structure of your text.
You can find the tokenizer tool at https://platform.openai.com/tokenizer. To use the tokenizer tool, simply enter the text you want to analyze and select the appropriate model and settings.
The tool will then generate a list of tokens, along with their corresponding byte offsets (see below figure).
The Tokenizer Tool
The ChatGPT API pricing is structured such that you are charged per 1,000 tokens processed, with a minimum charge per API request. This means that the longer your input and output texts are, the more tokens will be processed and the higher the cost will be. Table 1.2 displays the cost of processing 1,000 tokens for several commonly used ChatGPT models.
ChatGPT API Model Pricing
Important note
It is important to keep an eye on your token usage to avoid unexpected charges. You can track your usage and monitor your billing information through the Usage dashboard at
https:// platform.openai.com/account/usage
.
As you can see, ChatGPT has an easy-to-use interface that allows developers to interact with GPT models for natural language processing tasks. Tokens are the basic units of text used by the models to process and understand the input and output text. The pricing structure for the ChatGPT API is based on the number of tokens processed, with a minimum charge per API request.
In conclusion, this article has provided a comprehensive overview of the essential steps to embark on your journey with OpenAI and ChatGPT. We began by guiding you through the process of creating an OpenAI account, ensuring you have seamless access to the myriad tools offered by the company. We then delved into the ChatGPT web interface, showing you how to navigate its features effectively for productive interactions with the AI model. Moreover, we explored the ChatGPT API, highlighting its versatility and use cases in various NLP tasks. Understanding tokens and pricing was demystified, allowing you to make informed decisions. As you embark on your ChatGPT journey, you are well-equipped with the knowledge to harness its potential for your unique needs. Happy exploring!
Martin Yanev is an experienced Software Engineer who has worked in the aerospace and industries for over 8 years. He specializes in developing and integrating software solutions for air traffic control and chromatography systems. Martin is a well-respected instructor with over 280,000 students worldwide, and he is skilled in using frameworks like Flask, Django, Pytest, and TensorFlow. He is an expert in building, training, and fine-tuning AI systems with the full range of OpenAI APIs. Martin has dual master's degrees in Aerospace Systems and Software Engineering, which demonstrates his commitment to both practical and theoretical aspects of the industry.