Developer quickstart

Take your first steps with the OpenAI API.

The OpenAI API provides a simple interface to state-of-the-art AI models for text generation, natural language processing, computer vision, and more. This example generates text output from a prompt, as you might using ChatGPT.

Generate text from a model

1
import OpenAI from "openai";
2
const client = new OpenAI();
3
4
const completion = await client.chat.completions.create({
5
model: "gpt-4.1",
6
messages: [
7
{
8
role: "user",
9
content: "Write a one-sentence bedtime story about a unicorn.",
10
},
11
],
12
});
13
14
console.log(completion.choices[0].message.content);
Built with