Frequently Asked Questions
The Azure AI JavaScript SDK supports Node.js LTS versions 14.x, 16.x, and 18.x. For browser environments, the SDK works with any modern browser that supports ES6.
You can authenticate using any of the following methods:
- Azure Active Directory (DefaultAzureCredential)
- Azure API Key (AzureKeyCredential)
- Managed Identity (ManagedIdentityCredential)
See the Authentication guide for code snippets.
Yes. The SDK provides a stream option that returns an async iterator.
This allows you to process tokens as they arrive without waiting for the full response.
const client = new OpenAIClient(...);
for await (const token of client.getChatCompletionsStream(...)) {
console.log(token);
}
The SDK uses the Azure Core RetryPolicy by default with exponential backoff.
You can customize retry settings when constructing the client:
const client = new OpenAIClient(endpoint, credential, {
retryOptions: { maxRetries: 5, retryDelayInMs: 2000 }
});
Pass the maxTokens parameter in the request options.
The service will stop generating once the limit is reached.
const response = await client.getChatCompletions({
messages: [...],
maxTokens: 512
});
Yes. Set includeUsage to true in the request options,
and the response will contain a usage object with token counts.
const result = await client.getChatCompletions({
messages,
includeUsage: true
});
console.log(result.usage);
The complete reference is available at the API Reference page, which includes all classes, methods, and enumerations.