Skip to main content

OpenAI API

Access GPT-4 and other models for chat, completions, and embeddings to build AI-powered features.

Key Features

  • GPT-4 access
  • Embeddings
  • Fine-tuning

Setup

1

Create an API key

Go to platform.openai.com and create an API key from your account dashboard.
2

Store securely

Store your API key in environment variables (e.g. OPENAI_API_KEY)—never commit it to version control.
export OPENAI_API_KEY="your-api-key-here"
3

Install SDK

Install the OpenAI SDK for your preferred language:
npm install openai
4

Make your first request

Use the Chat Completions API for conversational AI:
import OpenAI from 'openai';

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

const completion = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Hello!" }
  ],
});

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

Features & Best Practices

  • Create an API key at platform.openai.com; store it in env vars (e.g. OPENAI_API_KEY)—never commit it.
  • Use the Chat Completions API for conversational AI; Structured Outputs for reliable JSON.
  • gpt-4o is fast and capable for most use cases; gpt-4o-mini is cheaper for high-volume tasks.
  • Embeddings (text-embedding-3-small) for search, RAG, and similarity—key for hackathon demos.

Hackathon Tips

  • Free tier credits are limited; monitor usage and switch to mini for non-critical calls.
  • Use system prompts to define behavior; few-shot examples improve consistency for demos.

Resources

OpenAI API Quickstart

Official quickstart guide for the OpenAI API

Watch: OpenAI Responses API intro

Community tutorial on using the OpenAI API

Build docs developers (and LLMs) love