Using OpenAI for API testing
Last modified on Fri 25 Jul 2025

Purpose

This guide explains how to create functional API tests using OpenAPI, OpenAI (ChatGPT), and Postman, with no prior experience needed.

Step 1: Generate Postman Collection + Tests with ChatGPT

Upload the OpenAPI file to ChatGPT and ask: Here is an OpenAPI 3.0 spec. Please generate a complete Postman collection (v2.1 format) with: - All endpoints - Example request bodies and headers - Functional tests for status codes (200, 201, 401, 404, 422) - Test response fields like user.id, user.email Use placeholder tokens where needed. Output raw JSON for Postman import.

Step 2: Import into Postman

  1. Open Postman.
  2. Click Import.
  3. Import the JSON file generated from ChatGPT.

postman-import.png

Step 3: Run Requests and View Test Results

  1. Open a request.
  2. Check the Body tab.
  3. Click Send to run it.
  4. Go to the Scripts tab, and use the Post-response Script section to write your test code.

postman-tests.png

Common Issue: 404 Not Found

Tip for Edge Cases

Duplicate a request, rename it, and modify input data to simulate errors like 422 or 401.

Summary

Small Tweaks, Big Difference

ChatGPT may not provide perfect results on the first try, but with a bit of experimentation and prompt refinement, it can produce highly effective and accurate outputs.

How Reliable is the Output from ChatGPT?

ChatGPT is quite effective for generating functional Postman collections from clean OpenAPI documentation, especially when: - The OpenAPI spec uses version 3.0 or newer. - Example request/response data is present. - Standard RESTful patterns are followed.

However, there are limitations:

In short: ChatGPT is great for scaffolding, but human review is essential for real-world test coverage.

Are There Other Tools for This?

Yes. Tools similar to ChatGPT that can help generate Postman collections or test scenarios from OpenAPI include:

These tools vary in output quality and may require some prompt tuning, but ChatGPT remains one of the most capable for this exact use case.