Unified.to
All articles

How to Get Your ChatGPT API Key (OpenAI) — and Connect It to Your Product


February 20, 2026

Updated May 2026

If you're building with ChatGPT (OpenAI's models like GPT-4.1), you'll need an OpenAI API key.

This guide walks through:

  1. Creating your OpenAI API key
  2. Setting up billing and usage limits
  3. Testing your first API call
  4. Using OpenAI through Unified's Generative AI API
  5. Connecting OpenAI to customer SaaS tools via [Unified MCP](/mcp)

Step 1: Create an OpenAI Account

Go to:

https://platform.openai.com

Sign up or log in.

You must create an organization before generating API keys.

Step 2: Generate an API Key

In the left sidebar:

API Keys → Create new secret key

Name it clearly (e.g., prod-backend, dev-testing). You can also restrict permissions and associate the key with a specific project if you're managing multiple applications.

Your key will be shown once. Copy and store it securely. OpenAI API keys start with sk- followed by alphanumeric characters. Project-scoped keys start with sk-proj-. If your key doesn't match either pattern, it may have been copied incorrectly.

Best practice: use environment variables.

macOS / Linux

export OPENAI_API_KEY="<your_key>"

Windows (PowerShell)

setx OPENAI_API_KEY "<your_key>"

Never:

  • Commit API keys to Git
  • Embed them in frontend code
  • Share them in logs or screenshots

Step 3: Set Up Billing

OpenAI's API uses usage-based pricing.

In the dashboard:

Settings → Billing

Add a payment method and configure:

  • Initial credits
  • Auto-recharge (optional)
  • Usage limits

Without billing configured, your key may be inactive.

Step 4: Set Usage Limits

To avoid unexpected charges:

Settings → Limits

Configure:

  • Soft limit (email warning)
  • Hard limit (automatic cut-off)

This is critical for early-stage AI features where usage can spike unexpectedly.

Step 5: Test Your API Key

OpenAI's current standard endpoint is the Responses API.

Example:

curl https://api.openai.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4.1-mini",
    "input": "Write a two sentence summary of what an API key is."
  }'

If successful, you'll receive a JSON response containing the model output.

Is the OpenAI API free?

No. The ChatGPT web app has a free tier, but the API does not.

New accounts do not receive automatic free credits. The earlier $18 trial credit program no longer applies to newly created accounts. Most users need to add a payment method before API calls will succeed.

A few conditional paths exist:

  • OpenAI's Researcher Access Program offers up to $1,000 in API credits for approved researchers
  • Some startup accelerator and perks programs include OpenAI credits, though these are not guaranteed
  • Microsoft for Startups no longer bundles direct OpenAI platform credits; that program now offers Azure credits, which can be used with Azure OpenAI

API usage is billed per token. Rates vary by model — smaller models like gpt-4.1-mini cost significantly less than flagship models. Check the OpenAI pricing page for current rates before choosing a model for production.

Azure OpenAI API keys (different flow)

If your organization runs on Azure, you likely want an Azure OpenAI API key rather than a direct OpenAI key. The two are not interchangeable.

Azure OpenAI uses a different auth header (api-key instead of Authorization: Bearer), a different base URL ({your-resource}.openai.azure.com), and deployment-specific endpoint paths rather than model names. The OpenAI SDK works against Azure but requires Azure-specific configuration.

To get an Azure OpenAI API key:

  1. Create an Azure subscription with Azure OpenAI Service access
  2. Create an Azure OpenAI resource in the Azure Portal
  3. Go to the resource's Keys and Endpoint page
  4. Copy Key 1 or Key 2 and the endpoint URL
  5. Store as AZURE_OPENAI_API_KEY

Azure OpenAI gives you OpenAI models inside Azure's compliance and network boundary — useful for enterprise requirements around data residency, private networking, and procurement. If you don't have those requirements, the direct OpenAI API is simpler to set up.

How OpenAI API keys compare to other LLM providers

If you're integrating more than one model provider — or evaluating which to use — auth patterns, endpoint structures, and environment variable conventions differ enough to cause friction. Here's how the providers Unified's Generative AI API supports compare:

ProviderAuth headerEndpointEnv varKey formatOpenAI SDK compatible?
OpenAIAuthorization: Bearerapi.openai.com/v1OPENAI_API_KEYsk- / sk-proj-✓ native
Anthropic Claudex-api-keyapi.anthropic.com/v1ANTHROPIC_API_KEYsk-ant-
Google Geminix-goog-api-keygenerativelanguage.googleapis.com/v1betaGEMINI_API_KEYAIza...
X.ai GrokAuthorization: Bearerapi.x.ai/v1XAI_API_KEYnot publicly documented
GroqAuthorization: Bearerapi.groq.com/openai/v1GROQ_API_KEYgsk_...
Mistral AIAuthorization: Bearerapi.mistral.ai/v1MISTRAL_API_KEY32-char opaque token
CohereAuthorization: Bearerapi.cohere.ai/v1CO_API_KEYnot publicly documented✗ (own SDK)
DeepSeekAuthorization: Bearerapi.deepseek.com/v1DEEPSEEK_API_KEYsk-...
Hugging FaceAuthorization: Bearerapi-inference.huggingface.coHF_TOKENhf_...partial (chat only)
Azure OpenAIapi-key{resource}.openai.azure.comAZURE_OPENAI_API_KEYnot publicly documented✓ (via Azure SDK)
AnyScale¹Authorization: Bearerapi.endpoints.anyscale.com/v1ANYSCALE_API_KEYesecret_...
¹ Effective August 1, 2024, Anyscale Endpoints is available exclusively via the Hosted Anyscale Platform; multi-tenant LLM access was removed.

Three patterns worth noting before you build:

  • Anthropic and Gemini don't use Authorization: Bearer — Anthropic uses x-api-key, Gemini uses x-goog-api-key. Swapping providers isn't a one-line change if you're calling the REST API directly.
  • OpenAI SDK compatibility varies — Groq, DeepSeek, Grok, and AnyScale work with the OpenAI SDK by swapping the base URL. Anthropic, Gemini, and Cohere require their own SDKs or clients.
  • Cohere's env var is CO_API_KEY, not COHERE_API_KEY — a common misconfiguration when setting up multi-provider environments.

Troubleshooting common OpenAI API key errors

invalid_api_key — "Incorrect API key provided" The key in your Authorization header is wrong, malformed, or revoked. Check that:

  • The key starts with sk- or sk-proj-
  • There are no extra spaces or line breaks
  • The key hasn't been rotated or deleted in the dashboard

Regenerate at platform.openai.com/api-keys and update your environment variable.

insufficient_quota — "You exceeded your current quota" Billing isn't configured, your credit balance is exhausted, or you've hit your hard limit. Add a payment method under Settings → Billing and verify your balance. If you've set a hard usage limit, raise it or add credits.

rate_limit_exceeded (HTTP 429) You've hit the RPM or TPM limits for your current OpenAI usage tier. Check your current tier and limits in the OpenAI dashboard under Settings → Rate limits. Reduce burst traffic by adding exponential backoff, batching requests where possible, or caching repeated calls. If you're consistently hitting limits, you can request a tier increase from the dashboard once your account spend and status qualify.

Note: if you're calling OpenAI through Unified's Generative AI API, you may also see 429s enforced by Unified's own rate limits even when your OpenAI dashboard shows you're below your provider tier limits.

model_not_found — "The model does not exist or you do not have access to it" The model string in your request is wrong, misspelled, or your account tier doesn't have access yet. New models often roll out to higher-spend accounts first. Check the model name against the OpenAI models page and verify your account has access in the dashboard.

Authentication header malformed The Authorization header must be exactly Authorization: Bearer sk-... with no quotes around the key and no extra whitespace. This is the most common copy-paste error.

Key works locally but fails in production The environment variable isn't being read by your deployment environment. Verify OPENAI_API_KEY is set in your hosting platform's secrets or environment config — not just in your local .env file.

FAQ

Where do I find my OpenAI API key? At platform.openai.com/api-keys. Existing keys are listed there, but the full secret value is only shown at creation. If you've lost a key, generate a new one and revoke the old one.

What does an OpenAI API key look like? A string starting with sk- followed by alphanumeric characters. Project-scoped keys start with sk-proj-. Don't share either format — both grant API access billed to your account.

Is the OpenAI API key free? The key itself is free to generate. Using it is not. You need a payment method on file and sufficient credits before API requests will succeed. There is no ongoing free tier for the API.

What's the difference between a ChatGPT Plus subscription and an OpenAI API key? They are separate products with separate billing. ChatGPT Plus or Pro upgrades your experience in the ChatGPT web and mobile apps — it does not include any API credits. An OpenAI API key is for calling the same models programmatically in your own applications, billed per token. You can have one without the other. They share the same OpenAI account login but nothing else.

Can I use the same API key for dev, staging, and production? Technically yes, but you shouldn't. Use separate keys per environment so you can revoke one without impacting others, and so usage is clearly attributable per environment. Name keys accordingly: prod-backend, staging-api, dev-testing.

Why is my OpenAI API key not working? The most common causes: billing not configured, key was revoked or regenerated and the old value is still in your environment variable, the key was copied with extra whitespace, or you're calling a model your account tier doesn't have access to yet. Work through the troubleshooting section above.

How do I set the OPENAI_API_KEY environment variable? On macOS/Linux: export OPENAI_API_KEY="sk-..." in your shell config. On Windows PowerShell: $env:OPENAI_API_KEY = "sk-...". The OpenAI Python and Node SDKs read this variable automatically — you don't need to pass the key explicitly in code.

Does my OpenAI API key expire? Keys don't expire automatically, but OpenAI may disable keys detected in public repositories. Rotate keys quarterly as standard practice and immediately if you suspect exposure.

Using OpenAI in a Multi-Model AI Architecture

Calling OpenAI directly works if you only plan to use one provider.

Most AI-native SaaS teams eventually need:

  • Fallback between providers
  • Cost routing
  • Embedding portability
  • Enterprise flexibility

Instead of maintaining separate integrations for:

  • OpenAI
  • Gemini
  • Anthropic
  • Groq
  • Cohere

…you can integrate once using Unified's Generative AI API.

Build Once Across LLM Providers

Unified's Generative AI API standardizes:

  • Models
  • Prompts
  • Embeddings

Across supported providers — including OpenAI.

Core standardized objects

Model

  • id
  • max_tokens
  • temperature support

Prompt

  • model_id
  • messages
  • temperature
  • max_tokens
  • responses
  • tokens_used

Embedding

  • model_id
  • content
  • dimension
  • embeddings
  • tokens_used

This allows you to:

  • Route requests between OpenAI and other providers
  • Run the same prompt across models and compare output
  • Generate embeddings consistently
  • Keep your product logic stable

You write your GenAI integration once.

Let GPT Take Action with Unified MCP

Text generation is only half the system.

Production AI features require structured, authorized reads and writes against customer SaaS platforms:

  • List CRM deals
  • Retrieve ATS candidates
  • Fetch files
  • Update records
  • Write notes

Unified's MCP server connects OpenAI models to customer integrations in a controlled, authorized way.

OpenAI + Unified MCP (Remote MCP Example)

OpenAI supports remote MCP servers through the Responses API.

Example:

resp = client.responses.create(
    model="gpt-4.1",
    tools=[{
        "type": "mcp",
        "server_label": "unifiedMCP",
        "server_url": "https://mcp-api.unified.to/mcp?token=TOKEN&connection=CONNECTION",
        "require_approval": "never"
    }],
    input="List candidates and summarize their resumes."
)

When the model requests a tool:

  1. Call Unified's /tools/{id}/call
  2. Return the result to OpenAI
  3. Continue the response

This architecture separates responsibilities:

  • OpenAI → reasoning
  • Unified → authorized API execution
  • Your app → product logic and UX

Production Controls You Should Use

When deploying OpenAI with MCP:

  • Scope tools to avoid model overload
  • Restrict permissions per connection
  • Use regional MCP endpoints (US/EU/AU)
  • Monitor usage and API volume
  • Keep tokens server-side only

Unified's architecture is:

  • Real-time (data fetched directly from source APIs)
  • Pass-through
  • Zero storage of customer payloads
  • Usage-based pricing aligned to API volume

Why This Matters for AI-Native SaaS Teams

Calling GPT-4.1 is simple.

Shipping:

  • AI copilots
  • Agent-based write actions
  • Embedding pipelines
  • Enterprise-grade SaaS integrations

…requires infrastructure.

Unified was built for:

  • Real-time integration access
  • Pass-through architecture
  • Zero-storage design
  • MCP-compatible AI agents
  • Usage-based scaling

OpenAI generates intelligence.

Unified connects that intelligence to structured SaaS data and authorized actions.

That's how AI features move from demo to production.

→ Start your 30-day free trial

→ Book a demo

All articles