Back to blog
AIGuides & Tutorials

How to Get Your ChatGPT (OpenAI) API Key

This step-by-step guide walks you through everything from creating your account to generating and securing your first API key, setting up billing, and testing your integration.

Kateryna PoryvayKateryna Poryvay

Kateryna Poryvay

5 min read
How to Get Your ChatGPT (OpenAI) API Key

Step 1: Create an OpenAI Account

Navigate to platform.openai.com and click the "Sign up" button. You can register using your email address or sign up through your Google, Microsoft, or Apple account for faster access.

Screenshot 2025-08-29 at 17.34.41@2x

During registration, you'll need to verify your email address and provide a phone number for SMS verification. This two-factor authentication helps secure your account and prevent abuse of the API services.

Step 2: Access the API Dashboard

openai api key 2

Once your account is verified and you're logged in, you'll be directed to the OpenAI Platform dashboard. If you're not automatically redirected, go to platform.openai.com and sign in with your credentials. You will need to create an organization to generate API keys and start building.

openai api key 2

You will be prompted to invite your team, and then to make your first API call. After this step, you will be prompted to add some credits or billing details. You can always skip this step and click 'I’ll do this later.'

openai api key 3

Step 3: Navigate to your Dashboard

openai api key 4

In the left sidebar of your dashboard, locate and click on "API keys". You can also access this directly at platform.openai.com/api-keys.

This section displays all your existing API keys (if any) and allows you to create new ones or revoke old ones.

Step 4: Generate a New API Key

openai api key 5

Click the "Create new secret key" button. A dialog box will appear where you can:

  • Name your key (optional but recommended): Use descriptive names like "Production App" or "Development Testing" to help you identify different keys for different purposes
  • Set permissions: Choose whether this key should have full access or restricted permissions
  • Configure project association: Link the key to specific projects if you're managing multiple applications

Step 5: Save Your API Key Immediately

Critical: Once generated, your API key will be displayed only once. Copy it immediately and store it securely. OpenAI cannot retrieve or display this key again for security reasons.

Best practices for storing your key:

  • Use environment variables in your development environment
  • Store in secure key management systems (AWS Secrets Manager, Azure Key Vault, etc.)
  • Never commit API keys to version control systems like Git
  • Avoid hardcoding keys directly in your source code

Step 6: Set Up Billing

Before you can use your API key, you need to add billing information:

  1. Click on "Settings" in the sidebar, then select "Billing"
  2. Click "Add payment method" and enter your credit card details
  3. Set up usage limits (recommended for new users):
  • Configure monthly budget limits to prevent unexpected charges
  • Set up email alerts for when you approach your limits
  • Review the pricing page to understand costs per model and token usage

Note: If you add Credits to your account at the start, then you’ll be prompted to add your card details and set up billing.

Step 7: Test Your API Key

Verify your key is working with a simple test request. Here's a quick example using curl:


curl https://api.openai.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4.1",
    "input": "Tell me a three sentence bedtime story about a unicorn."
  }'

Replace YOUR_API_KEY_HERE with your actual API key. If successful, you'll receive a JSON response with the model's reply. Please check here for the complete documentation on the responses API.

Important Security Considerations

Protect your API keys like passwords. Anyone with access to your key can make requests that will be charged to your account. Follow these security guidelines:

  • Rotate keys regularly: Generate new keys periodically and revoke old ones
  • Use different keys for different environments: Separate keys for development, staging, and production
  • Monitor usage: Regularly check your usage dashboard for unexpected activity
  • Implement rate limiting: Add request throttling in your application to prevent abuse
  • Enable IP restrictions: If possible, restrict API key usage to specific IP addresses

Troubleshooting Common Issues

If you encounter problems:

  • "Invalid API key": Double-check you've copied the entire key correctly
  • "Insufficient quota": Ensure you've added billing information and have available credits
  • Rate limit errors: You may be hitting usage limits; check your plan's restrictions
  • Authentication failures: Verify the Authorization header format is correct:

Bearer YOUR_KEY

Managing Multiple Keys

For production applications, consider:

  • Creating separate keys for different services or microservices
  • Using key rotation strategies to minimize security risks
  • Implementing key management solutions for team environments
  • Setting up monitoring and alerting for each key's usage

Next Steps

With your API key ready, you can:

  • Integrate OpenAI's models into your applications
  • Explore different models (GPT-4, GPT-3.5-turbo, etc.)
  • Review the official API documentation
  • Set up webhooks for async operations
  • Implement proper error handling and retry logic

Remember to stay up to date with OpenAI's terms of service and usage policies, as these may change over time. Regular monitoring of your API usage and costs will help you optimize your integration and avoid unexpected charges.

Ready to get started?

Scale your integration strategy and deliver the integrations your customers need in record time.

Ready to get started?
Talk to an expert

Trusted by fast-moving product & engineering teams

Nmbrs
Benefex
Invoice2go by BILL
Trengo
Ponto | Isabel Group
Apideck Blog

Insights, guides, and updates from Apideck

Discover company news, API insights, and expert blog posts. Explore practical integration guides and tech articles to make the most of Apideck's platform.

How to Get Your Claude (Anthropic) API Key
AIGuides & Tutorials

How to Get Your Claude (Anthropic) API Key

This step-by-step guide shows you exactly how to create your Anthropic account, generate and secure your API key, set up billing, and test your first request.

Saurabh Rai

Saurabh Rai

6 min read
A Guide to Integrating with the NetSuite REST API
Unified APIGuides & TutorialsAccounting

A Guide to Integrating with the NetSuite REST API

Learn how to integrate with the NetSuite REST API, from OAuth 1.0a authentication setup to real-world implementation examples. Discover how Apideck's Unified Accounting API eliminates integration complexity and lets you connect to NetSuite & 20+ ERP applications.

Saurabh Rai

Saurabh Rai

12 min read
ERP API Integration: Understanding Business Cases and Technical Challenges
AccountingUnified API

ERP API Integration: Understanding Business Cases and Technical Challenges

Discover the strategic importance of ERP API integration in 2025, exploring business cases like cost savings and real-time data flow, alongside technical hurdles such as authentication, data normalization, and maintenance.

Saurabh Rai

Saurabh Rai

11 min read