@@ -5,6 +5,7 @@ import fetch from 'node-fetch';
5
5
import { HeadersInit } from "node-fetch" ;
6
6
import { RequestOptions , FinalRequestOptions , APIResponseProps , HTTPMethod , PromiseOrValue , DefaultQuery } from "./models" ;
7
7
import { APIPromise } from "./APIPromise" ;
8
+ import { AI21EnvConfig } from "./EnvConfig.js" ;
8
9
9
10
export type Headers = Record < string , string | null | undefined > ;
10
11
@@ -40,15 +41,13 @@ export abstract class APIClient {
40
41
41
42
constructor ( {
42
43
baseURL,
43
- maxRetries = 3 ,
44
- timeout = 300000 ,
45
- apiKey,
44
+ maxRetries = AI21EnvConfig . MAX_RETRIES ,
45
+ timeout = AI21EnvConfig . TIMEOUT_SECONDS ,
46
46
options,
47
47
} : {
48
48
baseURL : string ;
49
49
maxRetries ?: number | undefined ;
50
50
timeout : number | undefined ;
51
- apiKey : string ;
52
51
options : ClientOptions ;
53
52
} ) {
54
53
this . baseURL = baseURL ;
@@ -74,10 +73,13 @@ export abstract class APIClient {
74
73
}
75
74
76
75
protected getUserAgent ( ) : string {
77
- return `AI21 Typescript SDK ${ VERSION } ` ;
78
- }
76
+ const platform = this . isRunningInBrowser ( )
77
+ ? `browser/${ typeof window !== 'undefined' ? window . navigator . userAgent : 'unknown' } `
78
+ : `node/${ process . version } ` ;
79
+ return `AI21 Typescript SDK ${ VERSION } ${ platform } ` ;
80
+ }
79
81
80
- protected defaultHeaders ( opts : FinalRequestOptions ) : Headers {
82
+ protected defaultHeaders ( opts : FinalRequestOptions ) : Headers {
81
83
return {
82
84
Accept : 'application/json' ,
83
85
'Content-Type' : 'application/json' ,
@@ -141,7 +143,7 @@ export abstract class APIClient {
141
143
return { response, options, controller } ;
142
144
}
143
145
144
- protected static isRunningInBrowser ( ) : boolean {
146
+ protected isRunningInBrowser ( ) : boolean {
145
147
return (
146
148
typeof window !== 'undefined' &&
147
149
typeof window . document !== 'undefined' &&
0 commit comments