## Getting Started with the OpenAI API
The OpenAI API powers some of the most capable AI models available. This lesson covers everything you need to go from zero to making your first API call.
### API Key Management
Your API key is the gateway to OpenAI's models. Treat it like a password:
- Create keys in the OpenAI dashboard under API Keys
- Use environment variables — never hardcode keys in source code
- Rotate regularly — create new keys and deprecate old ones
- Set usage limits — configure spending caps per key and per project
```typescript // Good: environment variable const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
// Bad: hardcoded const openai = new OpenAI({ apiKey: "sk-..." }); ```
### SDK Installation
The official Node.js SDK provides type-safe access to all endpoints:
```bash npm install openai ```
The Python SDK mirrors the same interface:
```bash pip install openai ```
### Organization & Project Structure
OpenAI supports organizations and projects for team management:
- Organizations group billing and team members
- Projects isolate API keys and usage tracking
- Rate limits apply per-organization and can be customized
### Error Handling Patterns
Production applications must handle API errors gracefully:
- 429 Too Many Requests — implement exponential backoff
- 500 Internal Server Error — retry with delay
- 401 Unauthorized — check API key validity
- 400 Bad Request — validate inputs before sending