-
Notifications
You must be signed in to change notification settings - Fork 0
API Reference
gitpavleenbali edited this page Feb 17, 2026
·
2 revisions
Complete API reference for pyai.
| Module | Description |
|---|---|
| Configuration | Global configuration |
| One-Liner Functions | Simple AI operations |
| Agent | Agent class |
| Modules | Module reference |
Configure PyAI globally:
import pyai
pyai.configure(
api_key="sk-...", # API key
provider="openai", # "openai", "anthropic", "azure"
model="gpt-4o-mini", # Default model
azure_endpoint="...", # Azure OpenAI endpoint
temperature=0.7, # Default temperature
max_tokens=2048, # Default max tokens
)| Variable | Description |
|---|---|
OPENAI_API_KEY |
OpenAI API key |
ANTHROPIC_API_KEY |
Anthropic API key |
AZURE_OPENAI_API_KEY |
Azure OpenAI API key |
AZURE_OPENAI_ENDPOINT |
Azure OpenAI endpoint |
AZURE_OPENAI_DEPLOYMENT |
Azure deployment name |
Ask any question:
from pyai import ask
answer = ask("What is the capital of France?")
# With options
answer = ask(
"Explain quantum computing",
detailed=True,
format="bullet",
model="gpt-4"
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
question |
str |
required | Question to ask |
detailed |
bool |
False |
Comprehensive answer |
concise |
bool |
False |
Brief answer |
format |
str |
None |
"bullet", "numbered", "markdown" |
model |
str |
None |
Override model |
Deep research on any topic:
from pyai import research
result = research("quantum computing")
print(result.summary)
print(result.key_points)
print(result.insights)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
topic |
str |
required | Research topic |
quick |
bool |
False |
Quick summary only |
depth |
str |
"medium" |
"shallow", "medium", "deep" |
focus |
str |
None |
Focus area |
Summarize text or documents:
from pyai import summarize
summary = summarize("./document.pdf")
summary = summarize(long_text, max_words=100)Extract structured data:
from pyai import extract
data = extract(text, fields=["name", "date", "amount"])Translate text:
from pyai import translate
result = translate("Hello world", to="spanish")Generate content:
from pyai import generate
content = generate("blog post about AI", style="professional")Interactive chat:
from pyai import chat
session = chat(system="You are a helpful assistant.")
response = session.send("Hello!")Create intelligent agents:
from pyai import Agent
agent = Agent(
name="my-agent",
instructions="You are a helpful assistant.",
model="gpt-4",
skills=[my_skill],
memory=True
)
result = agent.run("What can you help me with?")See Agent for full documentation.
| Function | Description |
|---|---|
ask() |
Ask questions |
research() |
Research topics |
summarize() |
Summarize content |
extract() |
Extract data |
translate() |
Translate text |
generate() |
Generate content |
chat() |
Interactive chat |
agent() |
Create agents |
| Class | Description |
|---|---|
Agent |
Agent class |
LLMProvider |
LLM interface |
Memory |
Memory management |
| Class | Description |
|---|---|
Workflow |
Define workflows |
Pipeline |
Pipeline processing |
Blueprint |
Complex patterns |
| Module | Description |
|---|---|
vectordb |
Vector databases |
sessions |
Session storage |
plugins |
Plugin system |
@dataclass
class ResearchResult:
summary: str
key_points: List[str]
insights: List[str]
sources: List[str]
confidence: float@dataclass
class ExtractResult:
fields: Dict[str, Any]
confidence: floatfrom pyai.errors import (
PyAIError,
ConfigurationError,
APIError,
RateLimitError,
ValidationError
)
try:
result = ask("...")
except RateLimitError as e:
print(f"Rate limit: retry after {e.retry_after}s")
except APIError as e:
print(f"API error: {e.message}")For complete API documentation, see:
- Quick-Start - Getting started guide
- Configuration - Detailed configuration
- Agent - Agent class reference
- Workflows - Workflow patterns
Intelligence, Embedded.