Getting Started with OpenAI Responses API
Introduction & Goals
Welcome to your first lesson in building effective agents with GPT! Whether you're new to the OpenAI API or have some experience, this lesson will give you a solid foundation in structuring requests and interpreting responses — skills you'll reuse for agent workflows throughout this course.
In this lesson, you'll learn how to send messages using the Responses API and understand the complete response structure. By the end, you'll be able to create a script that communicates with a chat-capable model and inspect the full JSON response. This matters because, throughout the course, we'll be working with different parts of Responses API outputs — from basic text to reasoning summaries and conversation flow control.
The same patterns extend to more complex workflows later in the path, regardless of which compatible model you choose.
Environment and Setup
To communicate with GPT-5, you'll need two things: the OpenAI Node.js library and an API key from OpenAI. The library handles all the technical details of making API requests, and you'd normally install it through your package manager (for example, with npm install openai or yarn add openai). The API key authenticates your requests, and the OpenAI client automatically looks for it in the OPENAI_API_KEY environment variable.
In CodeSignal, we've already configured everything for you — the library is pre-installed and your API key is set up, so you can focus on learning the core concepts without worrying about setup details.
How the Responses API Handles Messaging
Every interaction follows a structured conversation pattern. The Responses API uses role-based messaging:
- The system role (passed via
instructions) sets behavior and context for the model — the model's "job description" for the conversation. - The user role represents messages from you or your end users.
- The assistant role represents model responses.
When you make a request, you provide a model, an instructions string, an input array representing the conversation history, and optional flags like store to control persistence. The API returns a structured JSON object containing the model's output and metadata — details we'll rely on later for reasoning tracking, conversation management, and error handling.
