Getting Started¶
This guide will take you from zero to a working forge application in under 5 minutes.
Prerequisites¶
- Python 3.11 or later
- An OpenAI API key (or any supported provider)
Step 1: Install¶
Optional extras
Install provider-specific extras as needed:
Step 2: Set your API key¶
Or create a .env file:
Step 3: Create your app¶
Create a file called main.py:
import asyncio
from forge.ai import complete, Message
async def main():
response = await complete(
messages=[Message.user("What is 2+2?")],
model="gpt-4o",
)
print(response.content)
asyncio.run(main())
Step 4: Run it¶
You should see:
That's it. You just made your first AI call with forge — with structured logging, retry handling, and token counting built in, all without any additional configuration.
What just happened?¶
Behind the scenes, forge automatically:
- Loaded configuration from your environment (no config files needed for simple usage)
- Initialized the runtime with default modules (AI, Config, Log, Retry)
- Created a logger with trace context propagation
- Sent the request to OpenAI with automatic retry on transient failures
- Returned the response with token usage metadata
Next Steps¶
- Explore all modules — deep-dive into each component
- Use with FastAPI — integrate forge into your web app
- Write a custom module — extend forge for your needs
- Browse recipes — common patterns and solutions