🔄 Big News! bazed.ai is now sagentic.ai. Same vision, new name!

Skip to content

@sagentic-ai/sagentic-af / Client

Client ​

OpenAI Client wrapper

Constructors ​

new Client(openAIKey, model, options) ​

ts
new Client(
   openAIKey,
   model,
   options?): Client

Create a new Client.

Parameters ​

• openAIKey: string

OpenAI API Key

• model: ModelType

Model to use

• options?: ClientOptionsExteded

ClientOptions

Returns ​

Client

Client

Source ​

src/client.ts:101

Properties ​

#openai ​

ts
private #openai: OpenAI;

OpenAI client

Source ​

src/client.ts:50


debug ​

ts
private debug: boolean = false;

Enable debug logging

Source ​

src/client.ts:82


inflightTickets ​

ts
private inflightTickets: Set<number>;

Set of inflight tickets

Source ​

src/client.ts:79


maxRetries ​

ts
private maxRetries: number = DEFAULT_MAX_RETRIES;

Maximum number of attempts to retry a failed request before giving up

Source ​

src/client.ts:74


model ​

ts
private model: ModelType;

Model to use

Source ​

src/client.ts:52


queue ​

ts
private queue: Ticket[] = [];

Queue of requests to be sent

Source ​

src/client.ts:55


requestPool ​

ts
private requestPool: number = 0;

Number of requests available for use

Source ​

src/client.ts:62


requestPoolMax ​

ts
private requestPoolMax: number = 0;

Maximum number of requests available for use

Source ​

src/client.ts:64


requestTimer? ​

ts
private optional requestTimer: Timeout;

Timer for resetting request pool

Source ​

src/client.ts:69


resetInterval ​

ts
private resetInterval: number = DEFAULT_RESET_INTERVAL;

Interval for fallback clearing limit counters

Source ​

src/client.ts:76


resetTimer? ​

ts
private optional resetTimer: Timeout;

Timer for clearing limit counters

Source ​

src/client.ts:67


tokenPool ​

ts
private tokenPool: number = 0;

Number of tokens available for use

Source ​

src/client.ts:58


tokenPoolMax ​

ts
private tokenPoolMax: number = 0;

Maximum number of tokens available for use

Source ​

src/client.ts:60


tokenTimer? ​

ts
private optional tokenTimer: Timeout;

Timer for resetting token pool

Source ​

src/client.ts:71

Accessors ​

RPM ​

ts
get RPM(): number

Number of allowed requests per minute

Returns ​

number

Source ​

src/client.ts:90


TPM ​

ts
get TPM(): number

Number of allowed tokens per minute

Returns ​

number

Source ​

src/client.ts:85

Methods ​

createChatCompletion() ​

ts
createChatCompletion(request): Promise<ChatCompletion>

Create a chat completion.

Parameters ​

• request: ChatCompletionCreateParamsNonStreaming

ChatCompletionCreateParamsNonStreaming

Returns ​

Promise<ChatCompletion>

Source ​

src/client.ts:269


enqueue() ​

ts
private enqueue(tokens, request): Promise<ChatCompletion>

Enqueue a request.

Parameters ​

• tokens: number

Number of tokens in the request

• request: ChatCompletionCreateParamsNonStreaming

ChatCompletionCreateParamsNonStreaming

Returns ​

Promise<ChatCompletion>

Source ​

src/client.ts:286


start() ​

ts
start(): void

Start the client. Must be called before using the client.

Returns ​

void

Source ​

src/client.ts:143


stop() ​

ts
stop(): void

Stop the client. Must be called when done using the client.

Returns ​

void

Source ​

src/client.ts:171


tick() ​

ts
private tick(caller): void

Tick the queue.

Parameters ​

• caller: string

Returns ​

void

Source ​

src/client.ts:304


updatePools() ​

ts
private updatePools(headers): void

Update pools based on API response.

Parameters ​

• headers: Headers

Returns ​

void

Source ​

src/client.ts:184