openai / openai-node

Official JavaScript / TypeScript library for the OpenAI API
https://www.npmjs.com/package/openai
Apache License 2.0
7.97k stars 870 forks source link

Setting `x-stainless-retry-count` to null in defaultHeaders gets ignored #1124

Closed spaceemotion closed 1 month ago

spaceemotion commented 1 month ago

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

Describe the bug

The recent addition of the x-stainless-retry-count header (https://github.com/openai/openai-node/commit/33e5e9b88f2cdb2ae90e355b394cb8c79f5e22a8) uses the local headers object, which does not include the default headers:

https://github.com/openai/openai-node/blob/785ef4b579637d3a6a205c0a9c51aa71987bf30e/src/core.ts#L391

To Reproduce

  1. Create a new OpenAI instance
  2. Set the defaultHeaders to include 'x-stainless-retry-count': null
  3. See the header being included nonetheless

Code snippets

No response

OS

Windows

Node version

Node v20

Library version

openai 4.67.1

felladrin commented 1 month ago

For readers looking for a workaround while this issue is open:

Setting "x-stainless-retry-count": null individually, in each request, works. For example:

const openai = new OpenAI(/* ...client config... */);

const modelsList = await openai.models.list({
  headers: {
    "x-stainless-retry-count": null,
  },
});

const completion = await openai.chat.completions.create(
  {
    /* ...completion config... */
  },
  {
    headers: {
      "x-stainless-retry-count": null,
    },
  },
);
RobertCraigie commented 1 month ago

Thanks for the report, this should be fixed in v4.68.1!