@@ -39,7 +39,11 @@ import type {
3939import type { Stream } from "openai/streaming" ;
4040import { version } from "../package.json" ;
4141import { encodingForModel , TiktokenModel , Tiktoken } from "js-tiktoken" ;
42- import { APIPromise } from "openai/core" ;
42+ // Type definition for APIPromise - compatible with both OpenAI v4 and v5+
43+ // The actual import is handled at runtime via require() calls in the _wrapPromise method
44+ type APIPromiseType < T > = Promise < T > & {
45+ _thenUnwrap : < U > ( onFulfilled : ( value : T ) => U ) => APIPromiseType < U > ;
46+ } ;
4347import {
4448 wrapImageGeneration ,
4549 wrapImageEdit ,
@@ -415,13 +419,13 @@ export class OpenAIInstrumentation extends InstrumentationBase {
415419 span : Span ;
416420 type : "chat" ;
417421 params : ChatCompletionCreateParamsStreaming ;
418- promise : APIPromise < Stream < ChatCompletionChunk > > ;
422+ promise : APIPromiseType < Stream < ChatCompletionChunk > > ;
419423 }
420424 | {
421425 span : Span ;
422426 params : CompletionCreateParamsStreaming ;
423427 type : "completion" ;
424- promise : APIPromise < Stream < Completion > > ;
428+ promise : APIPromiseType < Stream < Completion > > ;
425429 } ) {
426430 if ( type === "chat" ) {
427431 const result : ChatCompletion = {
@@ -608,8 +612,8 @@ export class OpenAIInstrumentation extends InstrumentationBase {
608612 type : "chat" | "completion" ,
609613 version : "v3" | "v4" ,
610614 span : Span ,
611- promise : APIPromise < T > ,
612- ) : APIPromise < T > {
615+ promise : APIPromiseType < T > ,
616+ ) : APIPromiseType < T > {
613617 return promise . _thenUnwrap ( ( result ) => {
614618 if ( version === "v3" ) {
615619 if ( type === "chat" ) {
0 commit comments