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 marvin

2) Set your environment variable

macOS / Linux:

export AIML_API_KEY=your-api-key

Windows 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 output

  • tools_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 outputs

  • Tools: register Python functions via Agent(tools=[...])

  • Token limits: increase output size if needed


Troubleshooting

Issue
Solution

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


Enjoy coding with Marvin + AI/ML API πŸš€

Last updated

Was this helpful?