Guilds AI / Blog

,

OpenAI API Platform: Setup, API Keys and First Request

Illustrative OpenAI API setup interface on a laptop with a masked key and a code editor.

The OpenAI API platform gives developers access to hosted AI models through an application programming interface. To get started, choose an authorized project, create a credential, install the official SDK and make a small Responses API request. This guide covers the developer dashboard, first request, model parameters and cost controls without assuming that a ChatGPT subscription includes API usage. For detailed token rates, cache pricing and worked estimates, see our OpenAI API cost calculator guide.

To compare the OpenAI platform with other types of AI service, see our AI API guide.

For diagnosing temporary provider failures separately from credential and billing errors, see our OpenAI API status and troubleshooting guide.

For the historical launch of the text and speech APIs and the transition to current interfaces, see our ChatGPT and Whisper API guide.

For model selection and illustrative token costs in a coding workflow, see our best GPT for coding guide.

What is the OpenAI API platform?

The OpenAI API platform lets software request AI capabilities from OpenAI’s hosted models. Unlike the ChatGPT website, the API is designed for applications and automated workflows. Developers choose a model and endpoint, submit a request, and handle the returned data in their own application.

The platform also manages organizations, projects, credentials, permissions, usage and billing. For example, a support application might use the Responses API to draft answers, an embedding model to retrieve relevant passages, or an audio endpoint to transcribe recordings. These are different operations with distinct model requirements and costs. A ChatGPT subscription does not automatically include separate API usage. If you are deciding between purchasing model access directly and through Microsoft, see our Azure OpenAI vs OpenAI API comparison.

This guide focuses on the OpenAI developer platform rather than AI APIs in general. OpenAI’s developer quickstart, API reference and project-management documentation were reviewed on December 4, 2026, alongside independent introductory material from Zapier, DataCamp and freeCodeCamp. Older tutorials can help explain concepts but should not be used as current model or endpoint references.

Create an API project and select access

Sign in at platform.openai.com with the account you intend to use. Select your authorized organization and an appropriate project. Organization owners can create new projects; other roles may need to be added to one by an administrator. Review data residency options when creating a project, if your organization requires them.

Use a dedicated project for a new application when you need a clear separation of credentials, resources and usage. Check billing and model access before running requests. Configure project-level permissions and any applicable spending controls. Confirm whether a budget setting is a notification threshold or an enforced cap before relying on it to stop charges.

How to create and store an OpenAI API key

In the platform’s organization settings, select the project and open API Keys. Choose Create new secret key, give the credential a recognizable name if available, and select the appropriate permissions. Store the value securely when it is displayed. If you lose a secret, create a replacement and revoke the obsolete credential when appropriate.

You do not normally find a developer API key in a ChatGPT conversation or its ordinary settings. Use the developer platform. Key strings may have recognizable prefixes, but the prefix alone cannot establish whether a credential is valid. Never share the full value, log it, or put it in browser JavaScript.

For a deployed workload, consider a project service account and, where supported, workload identity federation with short-lived credentials. A personal developer key is less appropriate for a shared production service. Our AI API security guide explains further access and data-handling controls.

How to use the ChatGPT API in Python

For a new text-generation integration, use the documented Responses API. Install the official Python SDK in a virtual environment using a supported Python release.

python -m pip install -U openai

Set OPENAI_API_KEY through your approved environment or secret manager. Set OPENAI_MODEL to a currently available model identifier from your project’s model access. The following original example asks the model to rewrite a fictional stock notice, limiting the output length.

import os
from openai import OpenAI

client = OpenAI(timeout=30.0, max_retries=0)
result = client.responses.create(
    model=os.environ["OPENAI_MODEL"],
    instructions="Rewrite the notice clearly. Preserve the facts.",
    input="Our fictional store is closed on Monday.",
    max_output_tokens=200
)

print(result.output_text)
print(result.usage)

Run the script only after checking the selected account and model’s pricing. The result should preserve the Monday closure, but the exact wording is not predetermined. Inspect the response status if output is missing or incomplete. This example follows the current SDK request structure; no live API call or paid generation was performed.

The output limit includes reasoning tokens where applicable, so a low limit may produce an incomplete result. Do not repeatedly increase it without checking the consequences for usage.

Choose model settings and supply the current date

The model identifier selects a particular model and its supported capabilities. Do not assume that every GPT family, including older GPT-5 models, remains available to every project. Check the model catalog and endpoint reference before selecting a model.

Temperature controls sampling variation for models that support it. A lower setting can reduce variation, but it does not guarantee determinism or factual correctness. Some reasoning models do not accept a custom temperature in certain configurations. Keep the default unless the chosen model’s documentation supports your intended setting.

If the application needs the current date, compute it on the server in the correct time zone and supply it explicitly. For example:

from datetime import datetime
from zoneinfo import ZoneInfo

today = datetime.now(ZoneInfo("America/New_York")).date().isoformat()
instructions = f"Treat {today} as today's local date in New York."

The date tells the model what day it is, not what happened that day. For current facts, retrieve information through a supported, authorized source and pass the relevant evidence. Do not rely on the model’s training data for live information.

Use an API wrapper and handle errors

A wrapper is application code that centralizes authentication, request settings and response handling. The official SDK already handles many HTTP details. Keep provider-specific code on the server and expose only the operations your users are authorized to call.

Distinguish authentication failures from invalid requests, rate limits and temporary service errors. Log a sanitized request identifier and error type, not secrets or entire sensitive prompts. Use bounded retries for genuinely transient failures, with particular care when a request may lead to a consequential application action.

Our chatbot API example demonstrates a local application endpoint with input validation and deterministic tests. For migrating an existing application from the retired Assistants API, see our Assistants API migration guide.

How to manage API costs

Check current per-model pricing and the pricing of any selected tools. A simple text request may incur input and output token charges, while hosted tools or persistent resources can have additional billing. Inspect the returned usage data and the project’s dashboard to understand actual consumption.

Before launching an application, set request-size limits, model allowlists, user quotas and monitoring. Establish a separate application-side cutoff if you need a strict budget. Do not assume a dashboard alert prevents subsequent requests.

Start with a small authorized test and compare its quality and consumption against your requirements. A cheaper model may not be economical if its output requires frequent retries or manual correction.

Before implementing requests in code, compare the interactive assistant and API testing environment in our ChatGPT vs OpenAI Playground guide.

Frequently asked questions

Is OpenAI API access the same as ChatGPT? No. ChatGPT is a user-facing product; the API is a developer service with separate access and billing.

Can I get a free API key? Creating a credential is distinct from obtaining free model usage. Review your account’s available credits and applicable pricing.

What does an OpenAI API key look like? It is an opaque secret string generated by the platform. Its exact format may vary. Do not use real keys as examples.

Do I need FastAPI? No. FastAPI is a Python web framework for building your own endpoints, not the OpenAI model service. You can call the model API directly from a Python script.

Does the API always know today’s date? Do not assume it has the correct application-local date. Supply the date and time zone when accuracy matters.