Python SDK
Install and configure the HINOW Python SDK to integrate over 100 AI models into Python applications with sync and async support.
The HINOW Python SDK provides full access to the HINOW REST API with Pydantic models, type hints, and both synchronous and asynchronous clients.
> Note: For API resource documentation with code examples, see the API Reference. This page covers Python SDK-specific features and configurations.
Installation
bash
pip install hinow-aiOr with Poetry:
bash
poetry add hinow-aiRequirements
- Python 3.8+
- httpx
- pydantic
Configuration
Basic Setup
python
from hinow_ai import Hinow
client = Hinow(api_key="your-api-key")Environment Variable
bash
export HINOW_API_KEY=your-api-keypython
# API key loaded automatically from environment
client = Hinow()Advanced Configuration
python
client = Hinow(
api_key="your-api-key",
base_url="https://api.hinow.ai",
timeout=120.0,
max_retries=3,
)Basic Usage
Chat Completions
python
from hinow_ai import Hinow
client = Hinow()
response = 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,
)
print(response.choices[0].message.content)Using Different Models
python
# OpenAI GPT-4o
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Explain machine learning"}],
)
# Anthropic Claude
response = client.chat.completions.create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Explain machine learning"}],
)
# DeepSeek
response = client.chat.completions.create(
model="deepseek-ai/deepseek-v3.2",
messages=[{"role": "user", "content": "Explain machine learning"}],
)Streaming
python
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Write a story about a robot"}],
stream=True,
)
for chunk in stream:
content = chunk.choices[0].delta.content or ""
print(content, end="", flush=True)Conversation with History
python
from hinow_ai import Hinow
class ChatBot:
def __init__(self, api_key: str, model: str, system_prompt: str = None):
self.client = Hinow(api_key=api_key)
self.model = model
self.messages = []
if system_prompt:
self.messages.append({"role": "system", "content": system_prompt})
def chat(self, user_message: str) -> str:
self.messages.append({"role": "user", "content": user_message})
response = self.client.chat.completions.create(
model=self.model,
messages=self.messages,
max_tokens=1024,
)
assistant_message = response.choices[0].message.content
self.messages.append({"role": "assistant", "content": assistant_message})
return assistant_message
def clear_history(self):
self.messages = [m for m in self.messages if m["role"] == "system"]
# Usage
bot = ChatBot("your-api-key", "gpt-4o", "You are a friendly assistant.")
print(bot.chat("Hello!"))
print(bot.chat("What did we talk about?"))Function Calling (Tool Use)
python
from hinow_ai import Hinow
client = Hinow()
response = 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"
)
message = response.choices[0].message
if message.tool_calls:
for tool_call in message.tool_calls:
print(f"Function: {tool_call.function.name}")
print(f"Arguments: {tool_call.function.arguments}")Image Generation
python
response = client.images.generate(
model="black-forest-labs/flux-1-schnell",
prompt="A programmer cat wearing glasses, cartoon style",
size="1024x1024",
quality="hd",
)
for image in response.data:
print(f"URL: {image.url}")Text-to-Speech
python
response = client.audio.speech.create(
model="openai/tts-1-hd",
input="Hello! Welcome to HINOW AI.",
voice="alloy",
speed=1.0,
response_format="mp3",
)
print(f"Audio URL: {response.url}")Speech-to-Text
python
with open("/path/to/audio.mp3", "rb") as audio_file:
response = client.audio.transcriptions.create(
model="openai/whisper-large-v3",
file=audio_file,
language="en",
)
print(f"Transcription: {response.text}")Embeddings
python
response = client.embeddings.create(
model="BAAI/bge-base-en-v1.5",
input="Machine learning is fascinating",
)
embedding = response.data[0].embedding
print(f"Dimensions: {len(embedding)}")Error Handling
python
from hinow_ai import Hinow
from hinow_ai import (
APIError,
AuthenticationError,
RateLimitError,
InvalidRequestError,
InsufficientBalanceError,
)
client = Hinow()
try:
response = client.chat.completions.create(
model="nonexistent-model",
messages=[{"role": "user", "content": "Hello"}],
)
except AuthenticationError:
print("Invalid API key")
except InsufficientBalanceError:
print("Insufficient balance")
except RateLimitError as e:
print(f"Rate limit reached")
except InvalidRequestError as e:
print(f"Invalid request: {e.message}")
except APIError as e:
print(f"API Error: {e.message}")Context Manager
python
from hinow_ai import Hinow
with Hinow() as client:
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

