Skip to content

OpenAI API

The OpenAI API lets your app send requests to OpenAI models and receive results it can use.

Visit OpenAI API

When do you need the API instead of ChatGPT?

Use ChatGPT to try an idea by hand. Use the OpenAI API when your app needs to request a result and decide what to do with it. API usage has separate billing. Eligible ChatGPT Pro and Business subscribers can claim API credits for an API organization they own and link.

For a deployed app, use its own project credentials on your server. An API key is a secret that lets a program make requests on your account. Keep it out of website code visitors can download. Give the app only the access it needs.

What should your app do if the result is incomplete?

Start with a narrow task, such as tagging a fictional support request for human review. A supported model can use Structured Outputs to match a format you define. The format might require a category chosen from a small list.

Your app still needs to check whether the category fits the request. Handle a refusal, an incomplete response and an unavailable model. Leave a path for someone to select a category manually. OpenAI also offers other features, such as Realtime, with their own setup and pricing.

What counts toward the bill and what can stop a request?

Check the current API rates for the model and feature you use. Text prices commonly list separate input, cached input and output rates per million tokens. A token is a small piece of text. Other features can add charges in different units.

Your project can hit a request or token rate limit even if you are below budget. A spend alert tells you when tracked cost reaches a threshold. OpenAI also documents optional hard monthly limits for a project or organization that can stop requests once tracked spend reaches the cap. Enforcement can take time, so a small amount of extra usage can be billed. Decide what people will see if requests stop.

How can you test a budget and privacy decision on paper?

Sketch a support tagging feature using made-up messages and rates. Leave credentials, customer data and the API out of the exercise.

  1. Keep only the words you need
    Draw a fictional ticket that says the delivery is late. Circle the short message needed for the tag and cross out the pretend name, address and order number.
  2. Estimate both directions
    Imagine 1,000 requests with 500 input tokens and 100 output tokens each. That is 500,000 input and 100,000 output tokens. At fictional rates of $1 and $4 per million respectively, model text would cost $0.90 before other fees. Use your chosen model’s real rates when planning a launch.
  3. Plan a result when the feature stops
    Draw the result for a valid tag and a limit error. Leave the ticket for manual review if tagging fails. Write how you would stop one user or repeated requests from using the whole budget.

What can be kept, and what should you record before switching models?

OpenAI says API inputs and outputs are not used to train its models unless you opt in. The API can still retain some data. Default abuse monitoring logs can contain prompts and replies and are retained for up to 30 days, with documented exceptions. Some features store data to provide their own functionality.

Check the retention rules for the exact endpoint and settings you use before sending private information. Keep your own field definitions, model name, test examples and fallback rules so you can rerun the same checks before changing versions or providers.