Package Exports
- @kudagon/azureai-client
- @kudagon/azureai-client/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@kudagon/azureai-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@kudagon/azureai-client
A lightweight, fully-typed TypeScript client for the Azure OpenAI Chat/Assistants API, designed for Node.js.
Supports file uploads, conversation state management, and response persistence.
β¨ Features
- π Full TypeScript support with IntelliSense
- π Works on Node 16+ (
undicipolyfill) and Node 18+ (nativefetch/FormData/Blob) - π File upload + cleanup helpers
- π¬ Conversation management (messages, assistants, threads)
- πΎ Save responses to JSON or text
- π Convenient helpers for raw and plain text responses
π¦ Installation
npm install @kudagon/azureai-clientπ Quick Start
import KudagonAzureAIClient from "@kudagon/azureai-client";
const client = new KudagonAzureAIClient({
endpoint: process.env.AZURE_OPENAI_ENDPOINT!, // e.g. https://my-resource.openai.azure.com
apiKey: process.env.AZURE_OPENAI_KEY!,
deploymentName: "gpt-4o-mini", // your deployment name
apiVersion: "2024-08-01-preview", // optional, defaults provided
});
// Add conversation messages
await client.add_message({ role: "system", content: "You are a helpful assistant." });
await client.add_message({ role: "user", content: "Tell me a joke about Nigerian economy." });
// Run the request
await client.fetch();
// Get just the assistantβs reply string
console.log(client.response());
// Or inspect the full raw JSON response
console.log(client.raw_response());
// Save to disk
await client.save_response({ file_name: "output.json" });βοΈ API Reference
new KudagonAzureAIClient(config: AzureAIConfig)
Create a new client instance.
Config options:
endpoint: stringβ Azure OpenAI endpoint (no trailing slash)apiKey: stringβ API key from AzuredeploymentName: stringβ Model deployment nameapiVersion?: stringβ Defaults to2024-08-01-previewtimeout?: numberβ Default30000msinitMsg?: stringβ Default system prompt
Core Methods
add_message(message: Message | Message[])
Add one or more chat messages (role: "user" | "assistant" | "system").
add_file(fileConfig: FileConfig)
Attach a file from disk (file_path) or raw content (raw_file + file_name).
set_options(options: GenerationOptions)
Override generation parameters (e.g., max_tokens, temperature, top_p).
fetch(): Promise<void>
Runs completion with the current state. Uploads files, creates/uses assistant + thread, and stores the last response.
response(): string
Returns just the assistantβs latest reply (string). Throws if no response is available.
raw_response(): CompletionResponse
Returns the full structured JSON response from Azure. Includes choices, token usage, finish reasons, etc.
save_response({ file_name, file_type }): Promise<void>
Persist the last response as .json or .txt.
get_state()
Inspect current conversation state (messages, files, options, assistant/thread IDs).
clear()
Reset messages, files, assistant, and thread state.
File Management
list_files()β List uploaded filesdelete_file(fileId)β Delete a file by ID
Assistant Management
delete_assistant()β Delete the current assistant
π οΈ Development
Clone and install:
git clone https://github.com/kudagon/azureai-client.git
cd kudagon-azureai-client
npm installBuild:
npm run buildπ Example with dotenv
import { config } from "dotenv";
import KudagonAzureAIClient from "@kudagon/azureai-client";
config(); // Load .env variables
const client = new KudagonAzureAIClient({
apiKey: process.env.AZURE_OPENAI_KEY!,
endpoint: process.env.AZURE_OPENAI_ENDPOINT!,
deploymentName: process.env.AZURE_OPENAI_DEPLOYMENT!,
apiVersion: process.env.API_VERSION!,
});
(async () => {
await client.add_message({ role: "system", content: "You are a Nigerian comedian." });
await client.add_message({ role: "user", content: "Give me a quick joke about Lagos traffic." });
await client.fetch();
console.log("Assistant:", client.response());
})();π License
MIT Β© Kudagon