Marvin
About
Marvin is a Python framework by PrefectHQ for building agentic AI workflows and producing structured outputs. It allows developers to define Tasks (objective-focused units of work) and assign them to specialized Agents (LLM-powered configurations). Marvin supports type-safe results via Pydantic models, integrates with multiple LLM providers through Pydantic AI, and enables orchestration of multi-agent threads for complex workflows.
Installation
1) Install Marvin
uv add marvin
# or
pip install marvin2) Set your environment variable
macOS / Linux:
export AIML_API_KEY=your-api-keyWindows PowerShell:
setx AIML_API_KEY "your-api-key"3) Example β Run an AI/ML API Agent
File: examples/provider_specific/aimlapi/run_agent.py
Run it:
4) Other Examples
More examples are available in the same directory:
github.com/PrefectHQ/marvin/tree/main/examples/provider_specific/aimlapi
structured_output.pyβ structured JSON outputtools_agent.pyβ agent with custom tools (dates, weather)
Tips
Profiles: use multiple configurations (default =
openai/gpt-5-chat-latest, budget =openai/o4-mini)Structured results: pass
result_type=...for typed outputsTools: register Python functions via
Agent(tools=[...])Token limits: increase output size if needed
Troubleshooting
401 Unauthorized
Check your API key and remove extra spaces
404 Model not found
Verify the model ID exists in your account
Network error
Whitelist api.aimlapi.com if behind VPN/proxy
Helpful Links
Dashboard: https://aimlapi.com/app
API Keys: https://aimlapi.com/app/keys
Models: https://aimlapi.com/models
Docs: https://docs.aimlapi.com
Marvin repository: https://github.com/PrefectHQ/marvin
Enjoy coding with Marvin + AI/ML API π
Last updated
Was this helpful?