hinow-ai
v1.0.7
Published
Official TypeScript/JavaScript SDK for the HINOW AI Inference API
Maintainers
Readme
Access 100+ AI models through a single unified API. Generate text, images, audio, video, and embeddings with simple API calls.
Installation
npm install hinow-ai
# or
yarn add hinow-ai
# or
pnpm add hinow-aiQuick Start
import Hinow from 'hinow-ai';
const client = new Hinow({ apiKey: 'hi_xxx' });
const response = await client.chat.completions.create({
model: 'deepseek-ai/deepseek-v3.2',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(response.choices[0].message.content);Features
- Chat Completions - Text generation with LLMs
- Function Calling - Let AI call your functions
- Vision - Analyze images with AI
- Image Generation - Create images from text
- Text-to-Speech - Convert text to audio
- Speech-to-Text - Transcribe audio to text
- Video Generation - Create videos from text/images
- Embeddings - Generate text embeddings
- Streaming - Real-time response streaming
Chat Completions
Basic Chat
const response = await client.chat.completions.create({
model: 'deepseek-ai/deepseek-v3.2',
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);Streaming
const stream = await client.chat.completions.create({
model: 'deepseek-ai/deepseek-v3.2',
messages: [{ role: 'user', content: 'Tell me a story' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0].delta.content || '');
}Vision (Image Analysis)
const response = await client.chat.completions.create({
model: 'google/gemma-3-27b-it',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: "What's in this image?" },
{
type: 'image_url',
image_url: { url: 'https://example.com/image.jpg' }
},
],
},
],
});Function Calling
Let the AI call your functions to perform actions or retrieve data.
// 1. Define your tools
const tools = [
{
type: 'function' as const,
function: {
name: 'get_weather',
description: 'Get the current weather for a location',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'City name, e.g. Paris, London',
},
unit: {
type: 'string',
enum: ['celsius', 'fahrenheit'],
},
},
required: ['location'],
},
},
},
];
// 2. Send request with tools
const response = await client.chat.completions.create({
model: 'deepseek-ai/deepseek-v3.2',
messages: [{ role: 'user', content: 'What is the weather in Paris?' }],
tools,
tool_choice: 'auto',
});
// 3. Handle tool calls
const message = response.choices[0].message;
if (message.tool_calls) {
for (const toolCall of message.tool_calls) {
const args = JSON.parse(toolCall.function.arguments);
// Execute your function
const result = await getWeather(args.location, args.unit);
// Send result back to continue the conversation
const followUp = await client.chat.completions.create({
model: 'deepseek-ai/deepseek-v3.2',
messages: [
{ role: 'user', content: 'What is the weather in Paris?' },
message,
{
role: 'tool',
tool_call_id: toolCall.id,
content: JSON.stringify(result),
},
],
});
console.log(followUp.choices[0].message.content);
}
}Image Generation
Text to Image
const response = await client.images.generate({
model: 'black-forest-labs/flux-1-schnell',
prompt: 'A beautiful sunset over mountains',
aspect_ratio: '16:9',
output_format: 'jpeg',
});
console.log(response.data[0].url);Image to Image
const response = await client.images.edit({
model: 'stability-ai/sd3-turbo',
prompt: 'Transform into cyberpunk style',
images: ['https://example.com/photo.jpg'],
aspect_ratio: '1:1',
});
console.log(response.data[0].url);Audio
Text-to-Speech
const response = await client.audio.speech.create({
model: 'inworld/tts-1.5-max',
input: 'Hello, welcome to HINOW AI!',
voice_id: 'Ashley',
voice_gender: 'female',
language: 'English',
output_format: 'mp3',
});
console.log(response.audio_url);Speech-to-Text
const response = await client.audio.transcriptions.create({
model: 'openai/whisper-large-v3',
audio_url: 'https://example.com/audio.mp3',
language: 'en',
});
console.log(response.text);Video Generation
const response = await client.video.generate({
model: 'runway/gen-3-alpha',
prompt: 'A rocket launching into space',
aspect_ratio: '16:9',
});
console.log(response.data[0].url);Embeddings
const response = await client.embeddings.create({
model: 'BAAI/bge-base-en-v1.5',
input: ['Hello world', 'Goodbye world'],
});
// Access embedding vectors
console.log(response.data[0].embedding.length); // Vector dimensionsModels
List All Models
const models = await client.models.list();
for (const model of models.data) {
console.log(`${model.id}: ${model.name}`);
}Filter by Category
const imageModels = await client.models.list({
category: 'text_to_image'
});Get Model Details
const model = await client.models.retrieve('deepseek-ai/deepseek-v3.2');
console.log(model.context_window);Account
Check Balance
const balance = await client.getBalance();
console.log(`Balance: $${balance.balance}`);Configuration
const client = new Hinow({
apiKey: 'hi_xxx', // Required (or set HINOW_API_KEY env var)
baseURL: 'https://api.hinow.ai', // Optional: custom base URL
timeout: 120000, // Optional: request timeout in ms
maxRetries: 3, // Optional: max retry attempts
});Environment Variables
export HINOW_API_KEY=hi_xxx
export HINOW_BASE_URL=https://api.hinow.ai # Optional// API key will be read from environment
const client = new Hinow();Error Handling
import Hinow, {
AuthenticationError,
RateLimitError,
InsufficientBalanceError,
InvalidRequestError,
APIError,
} from 'hinow-ai';
try {
const response = await client.chat.completions.create({...});
} catch (error) {
if (error instanceof AuthenticationError) {
// Invalid or missing API key
console.log('Invalid API key');
} else if (error instanceof InsufficientBalanceError) {
// Not enough credits
console.log('Please add credits to your account');
} else if (error instanceof RateLimitError) {
// Too many requests
console.log('Rate limited, please retry later');
} else if (error instanceof InvalidRequestError) {
// Bad request parameters
console.log(`Bad request: ${error.message}`);
} else if (error instanceof APIError) {
// Other API errors
console.log(`API error [${error.statusCode}]: ${error.message}`);
}
}TypeScript Support
Full TypeScript support with type definitions included.
import Hinow, {
ChatCompletionRequest,
ChatCompletion,
ImageGenerateRequest,
ImageResponse,
} from 'hinow-ai';
const request: ChatCompletionRequest = {
model: 'deepseek-ai/deepseek-v3.2',
messages: [{ role: 'user', content: 'Hello!' }],
};
const response: ChatCompletion = await client.chat.completions.create(request);Supported Models
HINOW provides access to 100+ models across multiple providers:
| Category | Example Models | |----------|---------------| | Chat/LLM | DeepSeek V3, Gemma 3, Llama 3.3, Qwen 2.5 | | Image Generation | FLUX, Stable Diffusion 3, DALL-E 3 | | Text-to-Speech | ElevenLabs, OpenAI TTS, Inworld | | Speech-to-Text | Whisper Large V3 | | Video | Runway Gen-3, Kling, Minimax | | Embeddings | BGE, E5, OpenAI Embeddings |
Links
License
MIT © HINOW AI
