-
Notifications
You must be signed in to change notification settings - Fork 882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: getDefaultAgent is not a function #903
Comments
Hi @guidev, Thanks for the bug report, and I appreciate the repo example to reproduce the issue. Looking into it. |
@dgellow this is an issue with |
Thanks for reporting. Closing this issue as it seems like an It's possible we'll be able to substantially reduce or eliminate our Members of the community are welcome to share workaround here, but I encourage you to otherwise bring this up with |
One possible workaround you could try would be to explicitly |
@rattrayalex this isn't solved by importing the shim manually, that just results in a different error. The way to fix this is with the latest version of // loader.mjs
import { register } from "node:module";
register("import-in-the-middle/hook.mjs", import.meta.url, {
parentURL: import.meta.url,
data: { include: ["openai"]}, // this is the import bit here
}); Then running in node with |
FYI the loader.mjs workaround prevented the error in my project, but also stopped traces from being sent. The way I was able to fix this was by importing the openai web shims using the Start node like this:
When initializing the openai client: import 'http'
import OpenAI from 'openai'
const openai = new OpenAI({
httpAgent: new http.Agent()
}) And it all works! Same steps apply if you're using Anthropic btw. |
@tokisherbakov const openAiApiUrl = "https://api.openai.com/v1/chat/completions";
const response = await fetch(openAiApiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${appConfig.openAiKey}`,
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [...messages],
max_tokens: 256,
}),
}); |
Confirm this is a Node library issue and not an underlying OpenAI API issue
Describe the bug
When using openai-node with langchain and datadog, ESM, I get the following error:
To Reproduce
Code snippets
No response
OS
macOS
Node version
node 20, node 22
Library version
4.52.0
The text was updated successfully, but these errors were encountered: