What is the OpenAI API?
Short answer
The OpenAI API is a programming interface that integrates OpenAI's artificial intelligence models into a site, application or software. It can generate text, analyze documents, create images, process audio and automate tasks.
What is the OpenAI API?
The OpenAI API is a programming interface that allows developers to use OpenAI's artificial intelligence models in their own applications, websites or software.
- It acts as a bridge between your application and OpenAI models.
- It allows you to send a request, such as a question or a statement, and then receive a response generated by AI.
- It usually works via HTTP requests authenticated by an API key.
- It can be used to create chatbots, generate content, summarize documents, analyze data, or automate tasks.
- Unlike ChatGPT, the API does not provide a ready-to-use interface: it is intended for technical integration.
How to get an OpenAI API key?
To get an OpenAI API key, create an account on the OpenAI platform, access your organization's management, create or select a project, and then generate a secret key in the API Keys section.
- Connect to the OpenAI platform.
- Access your organization's settings.
- Create a project or select an existing project.
- Open the API Keys section of the project.
- Click on "Create new secret key".
- Copy the key immediately and save it to a password manager, a secret safe or a secure environment variable.
- Give the key the most limited permissions possible according to the intended use.
OpenAI indicates that the secret key can no longer be viewed after its creation. If you lose it, you need to generate a new one and update your application.
- Each project has its own API keys.
- A key may have permissions "All", "Restricted" or "Read Only".
- For professional integration, prefer a restricted key rather than a key with all rights.
- Never store the key directly in the source code, in a public file or in a mobile application.
- Preferably use a server-side environment variable or secret management service.
Before putting the integration into production, test the key with a simple request, check the flow limits of your project and set up an expense tracking.
What is the difference between ChatGPT and the OpenAI API?
ChatGPT is a user-ready application, while the OpenAI API is an interface for developers to integrate OpenAI models into their own sites, applications or software.
- ChatGPT is used directly in a conversation interface.
- The OpenAI API is used from a site, mobile application, software or automated system.
- ChatGPT is suitable for writing, research, brainstorming or daily assistance.
- The API is suitable for creating a client chatbot, internal assistant, content generation tool or automation.
- With the API, the company retains more control over user experience, sent data, called models and integration into its tools.
- API billing is separate from ChatGPT subscription.
In practice, a company can use ChatGPT for its teams and the OpenAI API to offer AI functionality to its customers, automate a process or connect AI to its CRM, e-commerce site or internal software.
Is the OpenAI API paid?
Yes, the use of the OpenAI API usually pays off. To start a paid use, add a payment method in the billing settings of your API account. This invoice is separate from your ChatGPT subscription.
- The cost depends mainly on the chosen model, the functionality used and the volume of tokens consumed.
- The input tokens correspond to the elements sent to the template in the query.
- Output tokens correspond to the elements generated by the model in the response.
- Cached tokens can benefit from a different price thanks to the quick hiding.
- For some models of reasoning, the tokens of reasoning are not visible in the answer, but count in the output use.
- The use of tools, storage or specific features may result in separate billing.
A token may represent a character, a part of a word, a whole word or a punctuation sign. So it does not exactly correspond to a word.
To control the budget, set a monthly budget, activate alert thresholds, monitor consumption in the OpenAI dashboard and limit unnecessary calls. In particular, OpenAI recommends setting several expenditure thresholds, e.g. 90% and 95% of a monthly budget.
Flow limits also exist. They can be expressed as requests per minute, tokens per minute, queries per day or tokens per day, depending on the model and the level of use. They are defined at the organizational and project level, not at the individual user level.
How to secure an OpenAI API key?
To secure an OpenAI API key, never publicly share it, store it in an environment variable or secret manager, assign limited permissions to it, monitor its use and revoke it immediately in case of a leak.
- Never publish the key in a GitHub, GitLab, forum, public documentation, email or screenshot.
- Do not include it directly in the code of a mobile application, public website or JavaScript file that is accessible on the browser side.
- Store the key in a server-side environment variable or in a secret management service.
- Give each key minimum permissions.
- Create a separate key by project, environment or application to limit impact in case of compromise.
- Monitor usage and costs regularly to detect abnormal activity.
- Set spending limits and alert thresholds.
- Renew the keys periodically by removing the old ones and creating new keys.
- Check the code before pushing it into a public repository to make sure no key has been included.
- Be careful with third-party tools, libraries and platforms that request access to your API key.
If a key has been exposed, delete it immediately from the OpenAI dashboard, create a new one, update your application and review the usage history to identify an unusual activity.
The OpenAI API uses Bearer authentication: the key is transmitted in the HTTP Authority header. It must be loaded from an environment variable or secret management service on the server, not from the client-side code.
Discover the video lesson
This video explains what an API is, how applications communicate with each other and why APIs are essential to integration and automation. It provides the basis for understanding the functioning of an API.
What you will discover
- What an API is and its role in interconnecting applications.
- Why some applications can communicate with each other through APIs.
- How an API works through the example of Google Home and Spotify.
- The meaning of API: Application Programming Interface.
- How APIs make no-code tools and automations possible.
- The restaurant analogy to understand the role of an API between a user and a service.
- The main possible actions with an API: recover, create, modify and delete information.
- How to read API documentation and interpret a response in JSON format.
- How to test an API without code using Postman.
- Examples of APIs used for weather, cryptocurrency, images and accounts connections.
What you will be able to do
- What an API is and its role in interconnecting applications.
- Why some applications can communicate with each other through APIs.
- How an API works through the example of Google Home and Spotify.
- The meaning of API: Application Programming Interface.
- How APIs make no-code tools and automations possible.
- The restaurant analogy to understand the role of an API between a user and a service.
- The main possible actions with an API: recover, create, modify and delete information.
- How to read API documentation and interpret a response in JSON format.
- How to test an API without code using Postman.
- Examples of APIs used for weather, cryptocurrency, images and accounts connections.