Cloudflare Workers AI
Use Cloudflare Workers AI models with PraisonAI Agents
Point an Agent at Cloudflare Workers AI by setting your credentials and naming the model.
Quick Start
- Install
bash pip install "praisonaiagents[llm]" - Set credentials
bash export CLOUDFLARE_API_KEY=your-cloudflare-key export CLOUDFLARE_ACCOUNT_ID=your-account-id - Run an agent
python from praisonaiagents import Agent agent = Agent( instructions="You are a helpful assistant", model="cloudflare/@cf/meta/llama-3.1-8b-instruct", ) agent.start("Hello!")
How it works
The cloudflare/ prefix tells PraisonAI to route the request through litellm to Cloudflare Workers AI, which reads CLOUDFLARE_API_KEY, CLOUDFLARE_ACCOUNT_ID from your environment. See Provider Auto-Detection for how model strings are resolved.
Common Patterns
Pick a different model
Keep the cloudflare/ prefix and swap the rest for any model your Cloudflare Workers AI account offers.
from praisonaiagents import Agent
agent = Agent(
instructions="You are a helpful assistant",
model="cloudflare/@cf/meta/llama-3.1-8b-instruct",
)Tune the response with a config dict
Pass a dict to set temperature, token limits, or other options.
from praisonaiagents import Agent
agent = Agent(
instructions="You write short, friendly answers",
model={
"model": "cloudflare/@cf/meta/llama-3.1-8b-instruct",
"temperature": 0.3,
"max_tokens": 500,
},
)
agent.start("Give me three tips for better sleep.")Best Practices
Prefer the shortest form
Start with model="cloudflare/@cf/meta/llama-3.1-8b-instruct" and nothing else. Add a config dict only when you need to tune temperature or limits.
Set the provider key once via env
Export CLOUDFLARE_API_KEY, CLOUDFLARE_ACCOUNT_ID in your shell or .env file. Keep keys out of your code.
Keep model= canonical
Always use model=. The older llm= name still works but prints a deprecation warning. See Model Parameter.