in Blog

February 27, 2024

How Do I Use the OpenAI API and Find the API Key? Step by Step Guide for 2024


Edwin Lisowski

CSO & Co-Founder

Reading time:

17 minutes

AI technology has steadily become more powerful in recent years and is poised to transform even more industries in the future. According to recent reports, the Global AI market will be worth more than $1.5 trillion by 2030. [1] A PwC global AI study also shows that the global GDP will grow by $15.7 trillion by 2030, with China and North America accounting for the biggest economic gains, thanks to AI technology. [2] Recently, OpenAI, one of the leading AI research labs on the planet, released the OpenAI API. Unlike most AI systems that are designed for one use case, API can be used on virtually any task.

Read on as we break down everything you need to know about OpenAI API, what it does, and how to use it properly.

ContextClue get a demo

Addepto introduces ContextClue – a cutting-edge AI Text Analysis Tool to revolutionize your document analysis for business growth!

What is OpenAI API?

OpenAI API is a cloud interface hosted on Microsoft Azure. It gives users access to new pre-trained AI models developed by OpenAI, such as DALL-E, Codex, and GPT-3. OpenAI API is ideally designed to ensure users can add state-of-the-art AI capabilities to virtually any task available in the English language. Unlike most AI systems which are usually designed for one use case, the OpenAI API provides developers with a general-purpose text-in and text-out cloud platform.

Any programming language task can use the OpenAI API for various purposes, including semantic search, content generation, translation, sentiment analysis, and many others. Once you give the API any text prompt, it will return a text completion that matches the pattern you gave it.

It’s also worth noting that you can program the OpenAI API by simply providing it with a few examples of what you’d like it to do. The program’s success will mainly depend on how complex the task at hand is.

OpenAI API Applications: How It’s Used

The OpenAI API, specifically, serves as a gateway for developers to access OpenAI’s powerful models, including versions of GPT (Generative Pre-trained Transformer) and others, via a cloud-based service. It allows for easy integration of OpenAI’s AI capabilities into various applications and services.

Looking for innovative solutions?
Addepto is a Generative AI development company that can help you transform your business with cutting-edge technologies.

How to use the OpenAI API?

Using OpenAI API is simple and straightforward. To get started, ensure you follow these steps:

How to use the OpenAI API: step-by step

Create an OpenAI account

If you don’t already have an OpenAI account, you need to create one by following the steps on the OpenAI website. In Python development, you can install the OpenAI package using pip (pip install OpenAI). [3] On the other hand, if you’re using Node, you can install it using npm (npm install OpenAI). [4]

Once you’ve created an OpenAI account, you will receive a verification link in your email inbox. Proceed to click the link to verify your email address. After that, enter your email address and the password linked to your OpenAI account to log in to your OpenAI account dashboard. [5]

Generate the OpenAI API key

Once you’ve created your OpenAI account or logged into an existing one, you’ll see your name’s initials and profile icon at the top-right corner of the OpenAI dashboard. To generate an OpenAI API key, tap on your name to view the dropdown menu. Click the ‘View API keys’ option.

At this stage, you’ll see a window with the option ‘Create new secret key’ near the center. If you don’t have an Open API key, proceed to click this option to get one. Ensure you save this newly generated API key as soon as possible. This is because you won’t be able to see the full OpenAI API key again once the window closes.

Make a test call with the OpenAI API key

Using your OpenAI API key, ensure you make a simple text request to your chosen model endpoints to get a specific model’s details. You can do this using a server-side programming language like JavaScript (Node) or Python.

After authenticating the OpenAI API key, present data in a visually appealing user interface. Once you’re done, your application is now ready for real-world use.

Is the OpenAI API free?

You can create an OpenAI API key for free. OpenAI API and get a feel of the technology without incurring any cost. During the free tier, you can make unlimited API requests and access a smaller selection of OpenAI API models.

Once your $5 credit is used up or expires, you can enter your billing information and subscribe to one of OpenAI’s pay-as-you-go plans. The subscription plan you choose will give you a huge number of API requests and higher usage quotas. However, the price you pay will mainly depend on the AI model you choose and the number of tokens consumed.

The price is set per 1000 tokens. OpenAI defines tokens as pieces of words where 1000 tokens are equivalent to 750 words. For example, 1000 tokens usually cost $0.002 with the GPT-3.5-turbo and $0.02 with the Davinci model. [6]

On the other hand, the cost of OpenAI image processing models usually depends on image resolution. For instance, generating a 1024×1024 resolution image costs $0.02, 512×512 costs $0.018, and 256×256 costs $0.016.

In most cases, an OpenAI API model is relatively cheaper than a ChatGPT Plus subscription. However, this will depend on how much you use the OpenAI model.

How to get the OpenAI API key?

To obtain the OpenAI API key, you can follow these steps:

  1. Create an OpenAI Account: If you don’t already have an OpenAI account, navigate to the OpenAI website and sign up by clicking on the “Sign Up” button at the top right corner of the website. Fill in your details to create an account.
  2. Verify Your Account: After signing up, you will receive an email from OpenAI to confirm your account. Open this email and click on the verification link provided to ensure the security of your account.
  3. Log In: Return to the OpenAI website and click on the “Log In” button. Enter the username and password you used to sign up.
  4. Access API Keys: Once logged in, in the top right corner of your screen, you’ll see an icon with your account name. Click on it to open the dropdown menu, then click “View API keys”.
  5. Generate a New API Key: In the API keys section, you should see a button labeled “Create new secret key”. Click on this button to generate a new API key.
  6. Name Your Key: A box will pop up asking you to name your secret API key. It’s advisable to name it something that will help you identify its purpose.
  7. Save Your Key Securely: After naming your key, click the “Create secret key” button. You will then see your secret key generated. Copy this key and paste it into the application where you intend to use it.
  8. Set Usage Limits (Optional): To control how much you spend each month on the API, you can set usage limits by clicking on “Usage limits” in the left menu and entering figures for hard and soft usage limits.
  9. Billing Setup: OpenAI charges for API usage based on consumption. Ensure you have set up a payment method for billing by clicking on “Billing” in the left menu and then “Payment methods”. Enter your credit card and billing details, then click submit.
  10. Security Reminder: Keep your API key secure and do not share it with anyone for security reasons



Types of OpenAI API models

OpenAI API is usually powered by a wide selection of models with different capabilities and prices. Here is a list of the different types of OpenAI API models:

types of OpenAI API models


The GPT-3 API is a selection of natural language processing models that can understand and generate natural language. These models are highly trained in a host of text-related generation and transformation use cases such as copywriting, summarization, analyzing unstructured text, classification, and even translation. The GPT-3 API family consists of models such as Davinci, Curie, Babbage, and Ada.

Among these models, Davinci is the most powerful one, making it ideal for understanding complex commands, identifying relationships between various texts, and summarizing texts for a specific audience. Davinci can complete every task with a higher degree of accuracy and efficiency than other models.

Curie is also a powerful model, especially when it comes to sentiment analysis and text classification. But all this depends on an individual’s experience. Different people prefer Curie over other models for different reasons.

On the other hand, Babbage and Ada are most suitable for completing simple and straightforward tasks that don’t require complex analysis. Both models are the fastest and the least expensive of OpenAI’s natural language processing models.

In recent months, the prices for these models have dropped significantly. This is because engineers at OpenAI have discovered better ways to run the models efficiently at a fraction of the initial cost. As a result, OpenAI is able to pass these savings to users in the form of lower prices.

Read more about GPT-4 vs GPT-3: Main Differences


This is the newest API model by OpenAI. GPT-4 is so accurate and efficient that it’s bound to replace Codex models for coding tasks. GPT-4 comes in 8K and 32K variants. The 8K variant can process 8,192 tokens, while the 32K variant has a capacity of 32,768 tokens. To put this into perspective, 32,768 tokens are equivalent to about 50 pages of text.

GPT4, OpenAI model, generative AI, artificial intelligence, hardware, microchip


Codex is trained to translate text to code in various programming languages such as Perl, JavaScript, Swift, SQL, PHP, Go, TypeScript, Ruby, and Shell. [7] It is also suitable for code editing and code insertion.

Other use cases for Codex include turning comments into code, suitable API and library discovery, and rewriting code for better performance.

OpenAI offers two Codex models, namely code-Davinci-002 and code-Cushman-001. Code-Davinci-002 is the most powerful Codex model available. This model is particularly efficient at translating natural language to code. Even though code-Davinci-002 is the most capable, code-Cushman-001 happens to be slightly faster.


Whisper is an automatic speech recognition (ASR) system trained to convert audio into text. This model was trained on several hours’ worth of audio datasets collected from the web. It is also capable of performing other tasks, such as language detection, multilingual transcription, and speech translation.

You can use the OpenAI Whisper as a voice assistant, speech translator to English, and chatbot. You can also use the OpenAI model to transcribe real-time speech into subtitles and to take notes during meetings. If you have a working knowledge of Python language, you can always integrate Whisper into your applications. It’s worth noting that Whisper can transcribe speech in 99 languages [8] and translate them into English.

The endpoint usage of Whisper API is simple. All you need to do is feed the Whisper model with audio, then opt for the Openai.Audio. Transcribe or Openai.Audio. Translate option to transcribe or translate it respectively. It’s worth noting that both the translate and transcribe endpoints can only accommodate an audio file of up to 25MB. Fortunately, both endpoints support the most popular types of audio files, including m4a, mp3, mp4, wav, MPEG, MPGA, and webm.

Whisper API is priced at $0.06 per 10 minutes. For this price, users have an affordable alternative to translate their huge audio files into text.


This state-of-the-art generative AI technology allows users to create high-resolution images with text. This OpenAI API is capable of generating entirely new images in various styles as specified by a user’s prompts. The name ‘DALL-E’ is a blend of Spanish artist Salvador Dalli and the Disney WALL-E movie.

DALL-E mainly relies on deep learning models and the GPT-3 API natural language processing model to understand natural language prompts and create new images.

DALL-E Open AI interface

OpenAI built DALL-E using a subset of the GPT-3 API large language model. However, instead of using the entire 175 billion parameters provided by the GPT-3 API, DALL-E only uses about 12 billion parameters.

To prove that DALL-E was capable of correctly generating high-resolution images, OpenAI built the Contrastive Language-Image Pre-Training (CLIP) model. The CLIP model was trained using 400 million labeled images. Afterward, OpenAI used CLIP to train DALL-E and determine the ideal captions for generated images. [9]


Embeddings are a selection of models that convert text into numerical forms. An embedding model is usually used to compare the relationship between two pieces of text. The embedding API uses the text-embedding-ada-002 model, to determine the relationship between two texts based on the distance between two vector points. The narrower the distance, the more related the texts under comparison are.

Embedding API is useful for text searching, recommendations, anomaly detection, sentiments, and classification. The text-embedding-ada-002 model usually costs $0.0004 per 1000 tokens.

Even though OpenAI says you can use first-generation embedding models for your tasks, you should know that the newer model is cheaper and performs better. OpenAI has also come forward to warn users that first-generation models might show a certain degree of bias towards certain people.

What is ChatGPT?

ChatGPT has been built using TensorFlow, PyTorch, and Python programming languages to provide it with the algorithms necessary to function properly. ChatGPT is thoroughly trained to have conversation-like interactions with users.

One of the main reasons ChatGPT is so popular among users is the fact that it keeps the context of an ongoing conversation. This creates room for follow-up questions and provides users with a chat-like experience. It’s also one of OpenAI’s most affordable models, priced at just $0.002 per 1000 tokens.

chatgpt, chatbot, language model, bot

It might be interesting for you: How can you use ChatGPT in business?

Can I use OpenAI API for commercial purposes?

Yes, you can use the content generated by any OpenAI API model for commercial purposes such as publication and sale, provided you comply with OpenAI’s terms and conditions. However, you’re solely responsible for ensuring the generated content doesn’t violate applicable law or the company’s terms.

Wrapping up

OpenAI APIs offer a wide variety of benefits to users looking to integrate AI technology into their applications. Whether you’re planning to build a custom AI model that can generate natural language, create high-resolution images, complete a coding project, or simply enhance the security and safety of your AI systems, OpenAI has an API that meets your needs.

Small businesses and large companies can rely on OpenAI API to automate repetitive tasks and improve their customer service in the long run. With OpenAI API’s ability to process large volumes of data and provide accurate results in real-time, this technology offers businesses a competitive edge.

Even though OpenAI API has accomplished a lot in its early stages, we expect the technology to continue improving as time goes by.

The OpenAI API – FAQ

  • What is the OpenAI API?

The OpenAI API provides access to OpenAI’s powerful artificial intelligence models, including various versions of GPT (Generative Pre-trained Transformer), Codex, and DALL·E. It allows developers to integrate AI functionalities into their applications, enabling a wide range of tasks like text generation, language translation, content creation, and more.

  • Can I use the OpenAI API for free?

OpenAI offers a limited amount of free usage as part of their API access, which is subject to change. Beyond this free tier, usage is billed according to the number of tokens processed. Check the OpenAI pricing page for the most current information.

  • Is there a limit to how many requests I can make to the OpenAI API?

Yes, OpenAI imposes rate limits and usage quotas to ensure fair access and manage server load. These limits vary by the plan you are on and can be found in the API documentation or your account’s API dashboard.

  • How secure is my data when using the OpenAI API?

OpenAI takes data security and privacy seriously. Data sent to and from the API is encrypted in transit, and OpenAI provides guidelines and settings to manage data retention policies. However, it’s important to review OpenAI’s privacy policy and ensure that your use of the API complies with all relevant data protection laws.

  • Can I fine-tune models with the OpenAI API?

As of my last update, OpenAI supports model fine-tuning for certain models and use cases. This allows you to train a model on your specific dataset to improve performance for your particular application. Check the OpenAI documentation for the latest information on supported models and how to start fine-tuning.

  • How can I keep my OpenAI API key secure?
  1. Do not hard-code your API key: Avoid embedding your API key directly in your code, especially if it’s shared publicly or stored in version control systems like Git.
  2. Use environment variables: Store your API key in environment variables to keep it separate from your application code.
  3. Limit access: Only share your API key with those who absolutely need it and consider using different keys for different environments or applications to limit access.
  4. Regularly rotate your API key: Change your API key periodically to minimize the risk of unauthorized access. You can generate a new API key and deactivate the old one from the OpenAI API dashboard.
  • What should I do if my OpenAI API key is exposed or compromised?
  1. Revoke the key immediately: Log in to your OpenAI account, navigate to the API dashboard, and deactivate or delete the compromised API key.
  2. Generate a new API key: Create a new API key to replace the compromised one.
  3. Audit your application: Check your application for any unauthorized use or suspicious activity that might have occurred using the compromised key.
  4. Implement better security practices: Ensure that your new API key is stored and used securely to prevent future exposures.
  • Can I have multiple OpenAI API keys?

Yes, OpenAI allows users to generate multiple API keys. This is useful for managing access in different environments (development, staging, production) or for different projects. You can create, manage, and revoke API keys from the OpenAI API dashboard.

  • How does OpenAI API key usage get tracked?

Usage is tracked at the API key level. OpenAI’s dashboard provides detailed reports on API usage, including the number of requests made, the compute time consumed, and the amount of data processed. This information helps you monitor your application’s API usage and understand billing.

  • Is there a way to restrict what my OpenAI API key can do?

OpenAI provides some mechanisms for limiting API key permissions, such as restricting access to specific IP addresses or setting usage limits. These settings can help you control how and where your API key is used, adding an extra layer of security to prevent misuse.

  • How does OpenAI API handle API key rotation?

OpenAI recommends regularly rotating your API keys for security reasons. You can rotate an API key by generating a new key and gradually transitioning your applications to use the new key before deactivating the old one. This process helps minimize potential disruptions to your service.

  • Are there any best practices for managing OpenAI API keys in a team?
  1. Use environment-specific keys: Assign separate API keys for development, testing, and production environments to control access and monitor usage more effectively.
  2. Limit distribution: Only share API keys with team members who need them to minimize the risk of accidental exposure.
  3. Use secret management tools: Leverage tools like HashiCorp Vault, AWS Secrets Manager, or Azure Key Vault to securely store and manage API keys, allowing secure access to keys without exposing them in code or configuration files.
  4. Educate your team: Ensure that all team members are aware of the importance of API key security and the best practices for managing and using these keys safely.

The article is an updated version of the publication from May 3, 2023.

Ebook: AI Document Analysis in Business


[1] AI Market Size Revenue Comparisons. URL: Accessed May 11, 2023
[2] AI Study. URL: Accessed May 11, 2023
[3] OpenAI Python. URL: Accessed May 11, 2023
[4] OpenAI-Node. URL: Accessed May 11, 2023
[5] Waitlist. URL: Accessed May 11, 2023
[6] Pricing. URL:, Accessed May 11, 2023
[7] Code Completion. URL: Accessed May 11, 2023
[8] How Big Of a Deal is Whisper for ASR Multilingual Transcription. URL:
[9] URL: Accessed May 11,2023


Generative AI

Artificial Intelligence