Home › OpenAI API tutorial for beginners

OpenAI API tutorial for beginners

Last checked

Every OpenAI API project starts the same way: a key in an environment variable, the official SDK, and one call to the Responses API.

Sign up and log in

  1. Sign in to the OpenAI developer platform and open the API keys page in the dashboard.
  2. Create an API key and store it somewhere safe.
  3. Export it as an environment variable: export OPENAI_API_KEY="your_api_key_here" (macOS/Linux) or setx OPENAI_API_KEY "your_api_key_here" (Windows).
  4. Install the official SDK: npm install openai, or pip install openai.
  5. The SDK reads the key from the environment automatically.

Step by step

  1. Create an API key in the dashboard and export it as OPENAI_API_KEY.
  2. Install the SDK: npm install openai (JavaScript) or pip install openai (Python).
  3. Create a client: const client = new OpenAI(); it picks up the key by itself.
  4. Call client.responses.create({ model: "gpt-6-astra", input: "…" }).
  5. Print response.output_text, then change the input and run it again.

Try it: examples

Good to know

Prices (US$)

Per million tokens on openai.com/api (standard rates under 272K context): GPT-6.1 Sol US$2.00 input / US$10.00 output, GPT-6.1 Terra US$1.00 / US$5.00, GPT-6 Luna US$0.10 / US$0.50, GPT-6 Astra US$10.00 / US$50.00.

Sources (official pages, read Nov 8, 2026)

Written from OpenAI's official documentation and product pages; we don't run hands-on tests. Features and limits vary by plan and country.

Report an error on this page