OpenAI Quickstart
Complete OpenAI onboarding guide for all platforms – Windows, macOS, and Linux
Get started with PraisonAI and OpenAI in under 5 minutes, with instructions that work on Windows, macOS, and Linux.
from praisonaiagents import Agent
agent = Agent(
name="Assistant",
instructions="You are a helpful AI assistant.",
)
agent.start("What is the capital of France?")The user installs PraisonAI, sets an API key, and runs their first agent in one session.
Quick Start
- Simple Usage
bash pip install praisonaiagents export OPENAI_API_KEY="<your-openai-api-key>"python from praisonaiagents import Agent agent = Agent( name="Assistant", instructions="You are a helpful AI assistant.", ) print(agent.start("What is the capital of France?")) - With Configuration
python from praisonaiagents import Agent agent = Agent( name="Research Assistant", instructions="You are an expert researcher.", model="gpt-4o", temperature=0.7, max_tokens=1000, ) print(agent.start("Summarise renewable energy trends"))Verify your setup with the CLI:
bash pip install praisonai praisonai doctor env --jsonmacOS/Linux
bash export OPENAI_API_KEY="<your-openai-api-key>"Windows PowerShell
powershell $env:OPENAI_API_KEY="<your-openai-api-key>".env file
env OPENAI_API_KEY=<your-openai-api-key>
How It Works
The agent workflow follows these steps:
| Step | Description |
|---|---|
| Create | Initialize agent with instructions and configuration |
| Execute | Process user input with OpenAI’s LLM |
| Return | Format and return the response |
Configuration Options
Environment Variables
| Variable | Description | Example |
|---|---|---|
OPENAI_API_KEY | Your OpenAI API key | sk-proj-abc123... |
OPENAI_BASE_URL | Custom API endpoint (optional) | https://api.openai.com/v1 |
OPENAI_MODEL | Default model (optional) | gpt-4o-mini |
Agent Configuration
from praisonaiagents import Agent
agent = Agent(
name="Research Assistant",
instructions="You are an expert researcher.",
model="gpt-4o", # Specify model
temperature=0.7, # Creativity (0-1)
max_tokens=1000, # Response length
output=True # Enable verbose output
)Common Patterns
Simple Q&A Agent
from praisonaiagents import Agent
agent = Agent(
name="Helper",
instructions="Answer questions clearly and concisely."
)
response = agent.start("Explain photosynthesis in simple terms")
print(response)Agent with Memory
from praisonaiagents import Agent
agent = Agent(
name="Personal Assistant",
instructions="Remember our conversation and provide personalized help.",
memory=True # Enable conversation memory
)
# First interaction
agent.start("My name is Alex and I like Python")
# Later interaction - agent remembers
response = agent.start("What programming language do I like?")
print(response)CLI Usage (requires pip install praisonai)
# Simple prompt
praisonai "What are the benefits of renewable energy?"
# Save output to file
praisonai "Write a haiku about coding" > poem.txt
# Use specific model
praisonai --model gpt-4o "Explain quantum computing"Advanced Features
Multi-Agent Teams
from praisonaiagents import Agent, Agents
# Create specialized agents
researcher = Agent(
name="Researcher",
instructions="Research topics thoroughly"
)
writer = Agent(
name="Writer",
instructions="Write clear, engaging content"
)
# Create team
team = Agents(agents=[researcher, writer])
result = team.start("Write a blog post about AI safety")
print(result)YAML Workflows
Create workflow.yaml:
framework: praisonai
topic: "Analyze market trends"
agents:
- name: "Data Analyst"
instructions: "Analyze market data and trends"
- name: "Report Writer"
instructions: "Create executive summaries"Run with:
praisonai workflow.yaml --framework praisonaiTools Integration
from praisonaiagents import Agent
agent = Agent(
name="Web Researcher",
instructions="Research topics using web search",
tools=["websearch"] # Enable web search tool
)
result = agent.start("Find the latest news about renewable energy")
print(result)Troubleshooting
'export' command not found (Windows)
Windows doesn’t recognize the export command. Use these alternatives:
PowerShell:
$env:OPENAI_API_KEY = $env:OPENAI_API_KEY # set in your shell firstCommand Prompt:
set OPENAI_API_KEY=%OPENAI_API_KEY%Permanent solution: Use a .env file in your project directory.
'praisonai' command not found
This means you installed praisonaiagents (Python SDK only) but need the CLI tools.
Solution:
pip install praisonaiThe packages serve different purposes:
praisonaiagents– Python SDK for scriptingpraisonai– CLI tools and YAML workflows
API key validation fails
If praisonai doctor env shows API key errors:
- Check the key format: Should start with
sk- - Verify environment: Run
echo $OPENAI_API_KEY(bash) orecho $env:OPENAI_API_KEY(PowerShell) - Use .env file: More reliable than environment variables
- Check permissions: Ensure you have valid OpenAI credits/usage limits
Encoding errors on Windows
If you see garbled text or encoding errors:
- Use JSON output: Add
--jsonflag to CLI commands - Check terminal encoding: Use Windows Terminal instead of Command Prompt
- Set encoding: Add
chcp 65001before running commands
Best Practices
Secure your API keys
- Never hardcode API keys in source code
- Use
.envfiles for local development - Set proper file permissions:
chmod 600 .env - Use environment variables in production
- Rotate keys regularly
Choose the right model
- gpt-4o-mini – Fast and cost-effective for simple tasks
- gpt-4o – Best performance for complex reasoning
- gpt-3.5-turbo – Good balance of speed and capability
- Start with gpt-4o-mini and upgrade as needed
Optimize for your use case
- Use
temperature=0for consistent, factual responses - Use
temperature=0.7-1.0for creative tasks - Set appropriate
max_tokensto control response length - Enable
memory=Truefor conversational agents
Monitor usage and costs
- Check your OpenAI dashboard regularly
- Set usage alerts in OpenAI console
- Use shorter prompts when possible
- Cache responses for repeated queries
Next Steps
Explore planning, reflection, and advanced reasoning capabilities
Multi-Agent TeamsBuild collaborative agent teams for complex workflows
Tools & IntegrationsAdd web search, file tools, and custom integrations
Memory & KnowledgeImplement persistent memory and knowledge bases