Tutorials

How to Get an OpenAI API Key: A Step-by-Step Guide

On this page

In this guide, you'll create an OpenAI account, generate your API key, and make your first API call. We'll also show you a simpler alternative if you want access to hundreds of AI models without managing multiple accounts.

Prerequisites

  • An email address (or a Google, Microsoft, or Apple account for single sign-on)
  • A payment method — OpenAI's API is usage-based
  • Basic familiarity with code (we'll show simple JavaScript examples)

Step 1: Create Your OpenAI Account

Go to platform.openai.com. This is the API platform, which is separate from chatgpt.com where you use ChatGPT.

Click Sign up and create your account using your email or SSO provider. Once you're in, you'll land on the API platform dashboard.

OpenAI platform sign-up page

If you already have a ChatGPT account, you can use the same credentials to log in. However, you'll still need to set up billing separately for API access.

OpenAI API platform dashboard

Before your API key will work, you need to add a payment method. Go to Settings → Billing and add a credit card. OpenAI charges per token, and pricing varies by model. Set a monthly spending limit here to avoid surprises — you can always increase it later.

Step 2: Generate Your API Key

In the left sidebar, click API keys, then click Create new secret key.

OpenAI API keys page in the sidebar

You'll see a few options:

  • Name — give it something descriptive like my-app-dev so you can identify it later
  • Project — assign it to a specific project if you have multiple (optional for most people starting out)
  • Permissions — choose the scope: full access, read-only, etc.

Click Create secret key.

OpenAI create new secret key dialog

Important: Copy the key immediately. OpenAI only shows it once. If you lose it, you'll need to generate a new one.

Store it somewhere safe — a password manager, an .env file, or your platform's secrets manager. Never commit API keys to a public repository.

OpenAI secret key revealed with copy button

Step 3: Make Your First API Call

Now you're ready to use the key. Here's a quick example using the OpenAI JavaScript SDK:

npm install openai
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

const response = await client.chat.completions.create({
  model: "gpt-5-nano",
  messages: [{ role: "user", content: "Hello, world!" }],
});

console.log(response.choices[0].message.content);

If you get a response back, everything is working.

One API Key, Hundreds of Models

The process above works well for OpenAI specifically — but what happens when you want to use Claude, Gemini, Llama, Mistral, or any of the other major models?

You'd need to repeat the entire process for each provider: create an account, set up billing, generate and manage a separate key. That's a lot of overhead, especially if you're experimenting or building something that uses multiple models.

Puter offers a simpler approach: one account, one auth token, access to hundreds of models across providers.

Instead of managing five different API dashboards, you point your existing code to Puter's OpenAI-compatible endpoint and use your Puter auth token:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.puter.com/puterai/openai/v1/",
  apiKey: "YOUR_PUTER_AUTH_TOKEN",
});

const response = await client.chat.completions.create({
  model: "gpt-5-nano", // or claude-sonnet-4-5, gemini-2.5-flash-lite, llama, etc.
  messages: [{ role: "user", content: "Hello, world!" }],
});

console.log(response.choices[0].message.content);

The code is almost identical — you're just pointing to a different URL and swapping the key. Switch between models by changing a single string.

To get your Puter auth token, create a free account at puter.com, then go to puter.com/dashboard and click Copy to grab your token.

Puter copy auth token

Conclusion

You now know how to create an OpenAI account, generate an API key, and make your first API call. For a deeper dive, check out OpenAI's official API docs.

Free, Serverless AI and Cloud

Start creating powerful web applications with Puter.js in seconds!

Get Started Now

Read the Docs Try the Playground