Getting Started with OpenAI Responses API
Introduction & Goals
Welcome to your first lesson in building effective agents with GPT! Whether you are new to the OpenAI API or have some experience, this lesson will provide you with a solid foundation in structuring requests and interpreting responses — skills you will reuse for agent workflows throughout this course.
In this lesson, you will learn how to send messages using the Responses API and understand the complete response structure. By the end, you will be able to create a script that communicates with a chat-capable model and inspects the full JSON response. This is important because, throughout the course, we will work 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, you will need two things: the OpenAI Ruby gem and an API key from OpenAI. The gem handles all the technical details of making API requests; you would normally install it by adding gem "openai", "~> 0.59.0" to your Gemfile and running bundle install, or directly with gem install openai -v 0.59.0. At the top of your script, you bring it in with require "openai". The API key authenticates your requests, and OpenAI::Client.new automatically reads it from the OPENAI_API_KEY environment variable.
In CodeSignal, we have already configured everything for you — the gem 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. In the Ruby client, the Responses API uses role-based messaging, where every message is a Ruby hash with a role key and a content array of typed content blocks:
- The
developerrole sets behavior and context for the model — the model's "job description" for the conversation. This message is passed directly inside theinputarray alongside all other messages, not as a separate field. - The
userrole represents messages from you or your end users. - The
assistantrole represents model responses.
A user or developer message follows this shape:
The content field is an array of typed blocks rather than a plain string. The type: "input_text" block is the standard way to pass text to the model. This typed structure gives the API flexibility to support multiple content types within a single message.
