Skip to content
trending

Guides

OpenAI API: Key Setup, Pricing, and Your First Request

Learn how to get an OpenAI API key, understand GPT-6 pricing, make your first API call in Python, and configure spending limits safely.

By 6 min read
OpenAI API: Key Setup, Pricing, and Your First Request

👁 115 reads

An OpenAI API key gives you programmatic access to OpenAI models, operating under a completely different model than a ChatGPT subscription: you pay per token instead of a flat monthly rate, allowing you to integrate models directly into your scripts, spreadsheets, and custom applications. Generating a key takes minutes at platform.openai.com, and running a first query in Python requires just five lines of code. Below is a walkthrough covering account setup, token pricing, your first API call, and key security practices.

Key Takeaways

A ChatGPT Plus subscription does not grant API access - it is a separate platform with its own prepaid billing system. The most affordable model in the current lineup, GPT-6 Luna, costs $0.10 per million input tokens and $0.50 per million output tokens, while GPT-6 Sol costs $2 and $10, and GPT-6 Astra costs $10 and $50. A simple website chatbot handling 10,000 conversations a month using Luna runs about $3. The API is designed for background automation without manual chat prompts; for everyday conversational use and writing, an end-user subscription remains the more convenient option.

What the OpenAI API Is and How It Differs from ChatGPT

The API is an access endpoint located at api.openai.com where an application sends text, images, or audio and receives a model completion in return. It does not include a persistent chat interface, built-in session history, or memory; any context the model needs must be included directly in the request payload. Usage is billed strictly by tokens: roughly 750 English words equal 1,000 tokens.

ChatGPT consumer tiers (Go, Plus, Pro) are managed via chatgpt.com and cover only the chat application. The developer platform resides at platform.openai.com, featuring an independent billing balance, separate invoices, and distinct rate tiers. While both can use the same email address, credit balances and subscription fees are not shared. For a breakdown on when each option is more cost-effective, read our guide on ChatGPT subscription vs. API, as well as our overview of ChatGPT pricing.

How to Generate an API Key Step by Step

  • Create an account: Go to platform.openai.com and sign in with an OpenAI account. The platform organizes projects, access keys, and billing under an organization profile.
  • Billing details: Navigate to Settings, Organization, Billing, and Billing details. If you represent a company, select “Business” and enter your tax ID or VAT number before adding funds, as existing invoices cannot be retroactively modified.
  • Add prepaid balance: Payments are processed via credit card upfront. Standard plans do not provide free starter credits; an initial deposit of $5 upgrades the account to Tier 1. You can enable or disable automated balance top-ups to prevent unexpected charges.
  • Generate a secret key: Head to platform.openai.com/api-keys, click “Create new secret key”, and assign it to a dedicated project with restricted permissions. Keys start with sk- and are displayed only once upon creation, so save them directly to a secure password manager.

Account spending and rate limits scale by tier according to OpenAI documentation:

Tier Requirement Monthly Spend Limit
Tier 1 $5 paid $100
Tier 2 $50 paid $500
Tier 3 $100 paid $1,000
Tier 4 $250 paid $5,000
Tier 5 $1,000 paid $200,000

Advancing through tiers also increases the requests-per-minute (RPM) and tokens-per-minute (TPM) allowances assigned to each individual model.

Model Pricing Breakdown

Rates are listed per million tokens based on official OpenAI developer pricing. Cached input refers to prompt data reused across subsequent queries (such as identical system instructions), which is billed at a discounted rate.

Model Input Cached Input Output
GPT-6 Astra $10 $1 $50
GPT-6 Sol $2 $0.20 $10
GPT-6 Luna $0.10 $0.01 $0.50
Batch API and Flex 50% discount off standard rates, with queued responses delivered within 24 hours
Long Context Higher rates apply, e.g. Astra increases to $20 input and $75 output

Here is how those numbers translate into real-world monthly costs across three practical scenarios:

  • Customer support FAQ bot: 10,000 conversations per month, averaging 1,500 input tokens (including prompt instructions) and 300 output tokens. On Luna: 15M input tokens × $0.10 + 3M output tokens × $0.50 = $3 total. On Sol, the same workload costs $60.
  • Document summarization pipeline: Processing 500 documents of roughly 10,000 tokens each into 500-token summaries. Running on Sol costs $12.50 standard, or $6.25 via the Batch API.
  • Data analytics assistant on Astra: 6,000 requests monthly averaging 8,000 input tokens (with 70% cache hit rate) and 1,500 output tokens. Input runs around $178 and output around $450, bringing the monthly total to roughly $628. This demonstrates that model tier selection impacts operating cost far more than request frequency alone.

To compare these rates with other AI providers accessible under a unified interface, explore our overview of OpenRouter pricing, or read our breakdown of GPT-6 Sol and Luna pricing tiers.

Your First API Request

Always store your API key in an environment variable rather than hardcoding it: use export OPENAI_API_KEY="sk-..." on macOS and Linux, or setx OPENAI_API_KEY "sk-..." on Windows. The official SDK detects this variable automatically. Below is an example using the Responses API (we tested it in Polish):

pip install openai

from openai import OpenAI
client = OpenAI()
response = client.responses.create(
    model="gpt-6-luna",
    input="Streść w dwóch zdaniach, czym jest token."
)
print(response.output_text)

The test prompt Streść w dwóch zdaniach, czym jest token. translates to: “Summarize in two sentences what a token is.”

You can execute the same query via curl by sending a POST request to https://api.openai.com/v1/responses with an Authorization: Bearer $OPENAI_API_KEY header and a JSON body specifying the model and input parameters. The Responses API serves as the primary endpoint, handling server-side conversation state, web browsing, and tool execution. Be prepared to handle common HTTP error codes: 401 (invalid authentication key), 429 (rate limit exceeded or depleted credit balance, where documentation recommends retrying with exponential backoff and jitter based on the Retry-After header), and 5xx (temporary service disruption).

Securing Your API Credentials

  • Never commit keys to a source repository or expose them in client-side code running inside a web browser; always proxy calls through your own backend server. Automated crawlers scan public repositories within minutes of a commit.
  • Generate separate keys per application or environment with restricted read/write scopes, and revoke unused credentials immediately.
  • Configure hard monthly spending limits and soft email notification thresholds under Billing, Limits. A runaway loop in code can otherwise exhaust a prepaid account balance overnight.
  • In the event of an exposure: revoke the compromised key immediately at platform.openai.com/api-keys, inspect usage logs in the Usage dashboard, issue a replacement secret, and scrub repository commit histories. According to research covered in our report on AI credential leaks, secret exposure incidents affect up to 98% of monitored organizations.

Frequently Asked Questions

Does the OpenAI API offer free trial credits?

Current OpenAI billing terms do not include complimentary trial credits. Accounts require an initial minimum balance deposit to send requests; adding $5 is sufficient to test thousands of queries using Luna.

Are API inputs and outputs used to train OpenAI models?

No. OpenAI documentation confirms that data submitted to the API after March 1, 2023 is not used to train models unless an organization explicitly opts in. Request logs are retained for abuse monitoring for up to 30 days. Eligible enterprise customers can apply for Zero Data Retention (ZDR), and regional processing is available via European endpoints at eu.api.openai.com.

How do business invoicing and tax IDs work?

For international customers outside the US, invoicing is typically handled via OpenAI Ireland Ltd. Entering a registered corporate Tax ID or VAT number in the billing panel ensures business invoices reflect the appropriate domestic or reverse-charge tax status. For an overview on managing foreign software subscriptions, see our article on paying for international AI tools.

Kinetyra

// read next

More on this from QUANTSLANT

Piotr Olszewski

Editor and publisher · Quantslant

I edit and publish Quantslant. AI tools help with research, drafts and translation; choosing topics, running the tests, checking facts and the decision to publish are mine, and so is the responsibility for what appears here.

read nextBest AI for Editing Reels: CapCut, OpusClip, or Descript?ai toolsBest AI for Editing Reels: CapCut, OpusClip, or Descript?CapCut is the best free editor for Reels, while OpusClip excels at repurposing long videos. Here is our hands-on test, pricing breakdown, and prompt.

Most read

  1. 1Best AI Video Generator Apps for Your Phone (2026)
  2. 2Claude Opus 5.5 Motion Graphics: 60s Showreel from One Prompt
  3. 3Wan 2.2 on RTX 4090: timings, VRAM and four test clips
// site map

This page in other languages6

Quantslant in numbers 1,423posts in archive22news from the last 7 days18video models in the observatory
🎬 AI Video Benchmarks: Higgsfield DoP vs OpenAI Sora • Higgsfield vs Runway Gen-3 • AI Video Credit Calculator
× ‹ enlarge ›