TypeScript SDK
Official TypeScript SDK for HINOW API with streaming and async support
TypeScript SDK
Install and configure the HINOW TypeScript SDK to integrate over 100 AI models into Node.js, Deno, Bun, and browser applications.
The HINOW TypeScript SDK provides full access to the HINOW REST API with complete TypeScript support, streaming, and modern async/await patterns.
> Note: For API resource documentation with code examples, see the API Reference. This page covers TypeScript SDK-specific features and configurations.
Installation
bash
npm install hinow-aiOr with other package managers:
bash
yarn add hinow-aibash
pnpm add hinow-aiRequirements
- Node.js 18+ (or Deno/Bun)
- TypeScript 4.7+ (optional but recommended)
Configuration
Basic Setup
typescript
import Hinow from 'hinow-ai';
const client = new Hinow({ apiKey: 'your-api-key' });Environment Variable
bash
export HINOW_API_KEY=your-api-keytypescript
// API key loaded automatically from environment
const client = new Hinow();Advanced Configuration
typescript
const client = new Hinow({
apiKey: 'your-api-key',
baseURL: 'https://api.hinow.ai',
timeout: 120000,
maxRetries: 3,
});Basic Usage
Chat Completions
typescript
import Hinow from 'hinow-ai';
const client = new Hinow();
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is the capital of France?' }
],
temperature: 0.7,
max_tokens: 1024,
});
console.log(response.choices[0].message.content);Using Different Models
typescript
// OpenAI GPT-4o
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Explain machine learning' }],
});
// Anthropic Claude
const response = await client.chat.completions.create({
model: 'claude-sonnet-4-20250514',
messages: [{ role: 'user', content: 'Explain machine learning' }],
});
// DeepSeek
const response = await client.chat.completions.create({
model: 'deepseek-ai/deepseek-v3.2',
messages: [{ role: 'user', content: 'Explain machine learning' }],
});Streaming
typescript
const stream = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Write a story about a robot' }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content || '';
process.stdout.write(content);
}Conversation with History
typescript
import Hinow from 'hinow-ai';
class ChatBot {
private client: Hinow;
private model: string;
private messages: Array<{ role: string; content: string }> = [];
constructor(apiKey: string, model: string, systemPrompt?: string) {
this.client = new Hinow({ apiKey });
this.model = model;
if (systemPrompt) {
this.messages.push({ role: 'system', content: systemPrompt });
}
}
async chat(userMessage: string): Promise<string> {
this.messages.push({ role: 'user', content: userMessage });
const response = await this.client.chat.completions.create({
model: this.model,
messages: this.messages,
max_tokens: 1024,
});
const assistantMessage = response.choices[0].message.content || '';
this.messages.push({ role: 'assistant', content: assistantMessage });
return assistantMessage;
}
clearHistory(): void {
this.messages = this.messages.filter(m => m.role === 'system');
}
}
// Usage
const bot = new ChatBot('your-api-key', 'gpt-4o', 'You are a friendly assistant.');
console.log(await bot.chat('Hello!'));
console.log(await bot.chat('What did we talk about?'));Function Calling (Tool Use)
typescript
import Hinow from 'hinow-ai';
const client = new Hinow();
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'user', content: 'What is the weather in New York?' }
],
tools: [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get the current weather for a location',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'City and state, e.g., New York, NY'
},
unit: {
type: 'string',
enum: ['celsius', 'fahrenheit']
}
},
required: ['location']
}
}
}
],
tool_choice: 'auto'
});
const message = response.choices[0].message;
if (message.tool_calls) {
for (const toolCall of message.tool_calls) {
console.log('Function:', toolCall.function.name);
console.log('Arguments:', toolCall.function.arguments);
}
}Image Generation
typescript
const response = await client.images.generate({
model: 'black-forest-labs/flux-1-schnell',
prompt: 'A programmer cat wearing glasses, cartoon style',
size: '1024x1024',
quality: 'hd',
});
for (const image of response.data) {
console.log('URL:', image.url);
}Text-to-Speech
typescript
const response = await client.audio.speech.create({
model: 'openai/tts-1-hd',
input: 'Hello! Welcome to HINOW AI.',
voice: 'alloy',
speed: 1.0,
response_format: 'mp3',
});
console.log('Audio URL:', response.url);Speech-to-Text
typescript
import fs from 'fs';
const response = await client.audio.transcriptions.create({
model: 'openai/whisper-large-v3',
file: fs.createReadStream('/path/to/audio.mp3'),
language: 'en',
});
console.log('Transcription:', response.text);Embeddings
typescript
const response = await client.embeddings.create({
model: 'BAAI/bge-base-en-v1.5',
input: 'Machine learning is fascinating',
});
const embedding = response.data[0].embedding;
console.log('Dimensions:', embedding.length);Error Handling
typescript
import Hinow, {
APIError,
AuthenticationError,
RateLimitError,
BadRequestError,
} from 'hinow-ai';
const client = new Hinow();
try {
const response = await client.chat.completions.create({
model: 'nonexistent-model',
messages: [{ role: 'user', content: 'Hello' }],
});
} catch (error) {
if (error instanceof AuthenticationError) {
console.log('Invalid API key');
} else if (error instanceof RateLimitError) {
console.log('Rate limit reached');
} else if (error instanceof BadRequestError) {
console.log('Invalid request:', error.message);
} else if (error instanceof APIError) {
console.log('API Error [' + error.status + ']:', error.message);
}
}Browser Usage
typescript
import Hinow from 'hinow-ai';
// Note: Never expose API keys in client-side code in production
// Use a backend proxy instead
const client = new Hinow({
apiKey: 'your-api-key',
dangerouslyAllowBrowser: true,
});

