Blog

Call OpenAI From Make With a Code Step (Structured Output You Can Map)

Updated November 2026

Make's native OpenAI app handles chat completions well, and for one prompt per bundle it is the right module. A code step earns its place when you need a JSON schema enforced answer that lands as mappable fields, when 50 items should go into one prompt instead of 50 operations, or when a 429 should retry with backoff inside the same step. The Execute Inline JavaScript module ships the openai npm package on every plan.

TL;DR

  • Use client.responses.create with text.format of type json_schema and strict: true. That is the API OpenAI's docs recommend for structured output (checked October 2026).
  • Return an object from the code step. Make shows its fields in the mapping panel of every following module, no Parse JSON step needed.
  • Classify 50 tickets in one call: 1 Make operation and 1 CustomJS request instead of 50 operations.
  • The openai SDK retries 429 and 5xx responses twice by default with exponential backoff; raise maxRetries or write your own loop.
  • If the native module's text answer only needs to become JSON, the AI JSON Parser module does that without code.

How do I get a JSON schema response from OpenAI that Make can map?

Put a Transform to JSON module in front of the code step so the tickets arrive as an array, map your OpenAI key from a Make variable into the same JSON, and set Return Type to Object. The script sends all tickets in one prompt, forces the answer into a schema, checks that one result came back per ticket, and returns the array.

Input (mapped into the Input field)

{
  "apiKey": "sk-proj-REDACTED",
  "tickets": [
    { "id": "T-1041", "text": "Charged twice for the October invoice" },
    { "id": "T-1042", "text": "Export to CSV button does nothing in Safari" },
    { "id": "T-1043", "text": "Would love a dark mode for the dashboard" }
  ]
}

JavaScript Code

const OpenAI = require('openai');

const data = typeof input === 'string' ? JSON.parse(input) : input;
const client = new OpenAI({ apiKey: data.apiKey, maxRetries: 4 });

const item = {
  type: 'object',
  properties: {
    id: { type: 'string' },
    category: { type: 'string', enum: ['billing', 'bug', 'feature', 'other'] },
    priority: { type: 'string', enum: ['low', 'medium', 'high'] },
  },
  required: ['id', 'category', 'priority'],
  additionalProperties: false,
};
const schema = {
  type: 'object',
  properties: { results: { type: 'array', items: item } },
  required: ['results'],
  additionalProperties: false,
};

const response = await client.responses.create({
  model: 'gpt-6-luna',
  input: [
    { role: 'system', content: 'Classify each ticket. One result per id.' },
    { role: 'user', content: JSON.stringify(data.tickets) },
  ],
  text: { format: { type: 'json_schema', name: 'tickets', schema, strict: true } },
});

const results = JSON.parse(response.output_text).results;
if (results.length !== data.tickets.length) {
  throw new Error(`Expected ${data.tickets.length} results, got ${results.length}`);
}
return { results };

Output (Return Type: Object)

{
  "results": [
    { "id": "T-1041", "category": "billing", "priority": "high" },
    { "id": "T-1042", "category": "bug", "priority": "medium" },
    { "id": "T-1043", "category": "feature", "priority": "low" }
  ]
}

With strict: true every object in the schema needs additionalProperties: false and every property listed under required; OpenAI rejects the request otherwise. The enum on category makes the field safe for a Make router: the model cannot answer "Billing issue" when the route expects billing. If the model refuses, output_text is empty, the parse throws, and the module reports an error instead of passing an empty batch on. Map results[] into an Iterator to continue one ticket per bundle.

The script itself adds about 121 ms (the median inline run); the rest is OpenAI's response time, which grows with batch size and model and stays inside the 30 s free-tier timeout (60 s on paid plans) for 50 short tickets. Model names and prices are from OpenAI's docs, checked October 2026: gpt-6-luna lists at $0.10 per million input tokens and $0.50 per million output tokens.

How do I retry OpenAI 429 errors with backoff inside the step?

The SDK already does this: by default it retries connection errors, 408, 409, 429 and 5xx responses two times with exponential backoff (openai-node README, October 2026), and maxRetries: 4 in the example raises that. For a longer wait or per-attempt logging, wrap the call yourself and set maxRetries: 0 so the two mechanisms do not stack:

const client = new OpenAI({ apiKey: data.apiKey, maxRetries: 0 });

async function withBackoff(fn, attempts = 5) {
  for (let i = 0; i < attempts; i++) {
    try {
      return await fn();
    } catch (err) {
      if (err.status !== 429 || i === attempts - 1) throw err;
      await new Promise((r) => setTimeout(r, 1000 * 2 ** i)); // 1s, 2s, 4s, 8s
    }
  }
}

const response = await withBackoff(() => client.responses.create({ /* as above */ }));

Five attempts with these delays wait about 15 s before the final try, which fits the 30 s free-tier limit.

Use our Make App to execute JavaScript directly in Make.

When should I use the native OpenAI module and when a code step?

Make's OpenAI app (checked October 2026) includes "Generate a completion", "Generate a response", "Transform text to structured data" and "Make an API call". Each processes one bundle per operation. The code step differs on four points:

NeedNative OpenAI moduleCode step (CustomJS)
Schema enforcementDepends on the module and its options; the answer arrives as text or a structured-data field you map afterwardsFull JSON schema with strict: true, enums and nested arrays, returned as a Make object
BatchingOne bundle per operationAny number of items per prompt, split back per item in the same step
Retries on 429A module error you route with an error handlerSDK backoff or your own loop, invisible to the scenario
Cost per 50 tickets50 Make operations1 Make operation plus 1 CustomJS request (600 per month free)

The code step bills per request, not per second, so a 6 s model response costs the same as a 1 s one. Make's own Code app bills 2 credits per second and ships no openai package below Enterprise. More packages: npm packages in Make.

When Make's built-in is enough

  • One prompt per bundle, free-text answer. Drafting a reply, summarizing a ticket, translating a message: "Generate a completion" does this in one operation and the answer maps as text.
  • You only need the text turned into JSON. If the native module returns something JSON-shaped and the only problem is code fences or a trailing comma, the AI JSON Parser module parses it with no code.
  • Low volume. Below a few hundred items a month, 1 operation per item is cheaper than thinking about batches.
  • Files, vector stores, images, transcription. The native app has dedicated modules for these; rebuilding them in code gains nothing.
  • A single extraction with a few fields. "Transform text to structured data" covers name, date and amount extraction from one text without a schema.

The free tier includes 600 requests per month and every npm package, no credit card. Paste the example into an Execute Inline JavaScript module, map your key and tickets, and run it once.

Get a free CustomJS API key

Frequently Asked Questions

Related Articles

Continue reading on similar topics

npm Packages in Make: What You Can Use on Which Plan
·Guide

npm Packages in Make: What You Can Use on Which Plan

Make's Code app ships moment, moment-timezone and lodash below Enterprise. CustomJS adds more than 40 npm packages on every plan, including free. Plan-by-plan table and a working example for dates, data, HTML, PDF, tokens, HTTP and SDKs.

makemake-comnpm