Ready to move beyond ChatGPT’s consumer model?

Playground (no code)

  1. Sign in to the OpenAI developer platform and open Playground: https://platform.openai.com/chat/

  2. Pick a model (start with a general one like GPT-5 class).

  3. In the left panel, set:

    • System: rules and role (e.g., “You are a precise writing coach. Return only JSON.”)

    • User: the actual task and data.

    • (Optional) Examples: one tiny example of ideal input → output.

  4. Temperature near 0.2–0.5 for accuracy; leave other defaults as is for now.

  5. Click Run. If you like the setup, Save it as a preset so you can reuse and A/B test later.

Tip: Playground is meant for fast experimenting without code. When you are ready to automate, switch to the API.

API in 10 minutes (code knowledge needed)

1) Get an API key (and keep it secret)

  • Create a key in your API Keys page.

  • Store it in an environment variable (never hard-code or use it directly in a browser app). OpenAI Help Center

2) Choose an API

  • Responses API (newer, flexible, supports built-in tools). Recommended for new builds. OpenAI

  • Chat Completions API (widely used, simple chat “messages”). Still fully supported.

3) JavaScript (Node.js)

Install

npm i openai

Responses API (recommended)

import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const res = await client.responses.create({
model: "gpt-4.1-mini", // Or whatever model you want.
input: "Say hello in 12 words, JSON only: {\"hello\": string}", // Pass a single string.
});
console.log(res.output_text);

(Responses API is the newer, unified interface for text, tools, and streaming.)

Chat Completions (messages with roles)

import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const chat = await client.chat.completions.create({
model: "gpt-4o-mini", // Or whatever version you want.
messages: [
{ role: "system", content: "You are a precise assistant. Reply with valid JSON only." },
{ role: "user", content: "Classify: 'App crashes on Pay'. Labels: critical|major|minor." }
]
});
console.log(chat.choices[0].message.content);

(“System/user/assistant” roles are the standard message structure in Chat Completions.) OpenAI Platform

4) Python

Install

pip install openai

Responses API

from openai import OpenAI
import os

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

res = client.responses.create(
model="gpt-4.1-mini", // or whatever version you want
input='Return JSON only: {"summary": string}. Summarize: "AI helps me write tests."'

)
print(res.output_text)

Chat Completions

from openai import OpenAI
import os

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
chat = client.chat.completions.create(
model="gpt-4o-mini", // or whatever version you want
messages=[
{"role": "system", "content": "You are a JSON-only assistant."},
{"role": "user", "content": "Give a 3-bullet plan for learning APIs."}
]

)
print(chat.choices[0].message.content)

5) Basics (same idea in Playground and API)

  • model: pick capability vs. cost/latency. Start strong, then optimize.

  • temperature: lower = more deterministic, higher = more creative.

  • max tokens / output tokens: cap the response length to avoid runaways. (See API reference.)

  • structure: ask for JSON/XML/CSV and validate before using downstream. (OpenAI supports “structured outputs” patterns.)

6) Safety and Setup Tips

  • Never expose your key in frontend code; route calls through your server.

  • If you hit “incorrect API key,” double-check the key and org settings.

  • You can assign key permissions and manage keys per project. OpenAI Help Center

Quick practice: run a format-locked check

Try this in Playground or Chat Completions:

System: “You are a strict JSON validator. Output only JSON.”
User: “List 3 breakfast ideas under 400 calories with a 1-sentence why.”
Expected:

{
"ideas": [
{"name":"Greek yogurt + berries","why":"High protein and fiber; low sugar."},
{"name":"Veggie omelet","why":"Protein rich; keeps you full."},
{"name":"Overnight oats","why":"Whole grains with consistent energy."}

]

}

If anything comes back with extra prose, tighten your System rules or lower temperature and re-run.