# The OpenAI SDK

The OpenAI API is a normal HTTPS API with an official Node package. The client reads your key from the OPENAI_API_KEY environment variable.

AI developers · Part 02: OpenAI API · Card 1 of 9 · Last updated 2026-10-13

## Analogy

Like the Stripe SDK: a typed wrapper around fetch, so you write client.chat.completions.create() instead of hand-building POST requests.

## Code example

`client.ts`

```typescript
// npm i openai zod dotenv
// .env -> OPENAI_API_KEY=sk-...
import OpenAI from "openai";

const client = new OpenAI(); // reads OPENAI_API_KEY
```

## In an agent

Every framework you'll meet later (LangChain, LangGraph, the Vercel AI SDK) is a wrapper around these same calls. Learn them raw first.

## Questions people ask

### How do I set up the OpenAI SDK in Node?

Run npm i openai, put your key in a .env file as OPENAI_API_KEY, and create a client with new OpenAI(). The client reads the key from the environment, so it never appears in your code. Keep this on the server: a key shipped to the browser can be copied and spent by anyone.

### Should I learn the raw OpenAI SDK before LangChain or the Vercel AI SDK?

Yes. Those frameworks wrap the same chat completion and tool calling requests. If you have made the raw calls yourself, you know what the framework is doing for you, you can debug it when something breaks, and you can answer the interview question about what the abstraction hides.

## Related concepts

- [Chat completion](https://studyvisually.com/learn/tech/ai-developers/openai-api/chat-completion)
- [Messages array](https://studyvisually.com/learn/tech/ai-developers/openai-api/messages-array)
- [Usage and cost](https://studyvisually.com/learn/tech/ai-developers/openai-api/usage-and-cost)
- [Structured output](https://studyvisually.com/learn/tech/ai-developers/openai-api/structured-output)

Web page: https://studyvisually.com/learn/tech/ai-developers/openai-api/openai-client
Study this card in the app: https://studyvisually.com/app/learn?category=ai-developers&card=openai-client
