Skip to content

responses.create parameter types #1547

Open
@seratch

Description

@seratch

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

When you have previous_response_id in the parameter list for responses.create method, the TypeScript compiler is not able to determine which of the overloaded methods to use.

To Reproduce

More specifically, the response object is any with an error in the following code:

import OpenAI from "openai";
const client = new OpenAI();

const instructions = `You're a helpful assistant.`;

let previousResponseId: string | undefined = undefined;
const outputs: string[] = [];

while (outputs.length < 5) {
  const input = `Write a haiku about programming. Don't repeat the words and phrases.`;
  // response' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)
  const response = await client.responses.create({
    model: "gpt-4.1",
    instructions,
    input,
    previous_response_id: previousResponseId,
  });
  previousResponseId = response.id;
  outputs.push(response.output_text);
}

console.log(JSON.stringify(outputs, null, 2));

A work around is to explicitly specify the parameter object type like this:

import { ResponseCreateParamsNonStreaming } from "openai/resources/responses/responses";

  // ....

  const params: ResponseCreateParamsNonStreaming = {
    model: "gpt-4.1",
    instructions,
    input,
    previous_response_id: previousResponseId,
    stream: false,
  };
  const response = await client.responses.create(params);

Code snippets

See the above part

OS

macOS but it should be any

Node version

v22.16.0 but probably any

Library version

^5.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions