Skip to content

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

pip install forge-kaif
Optional extras

Install provider-specific extras as needed:

pip install forge-kaif[openai]      # OpenAI support
pip install forge-kaif[anthropic]   # Anthropic support
pip install forge-kaif[ollama]      # Local Ollama support
pip install forge-kaif[all]         # All providers

Step 2: Set your API key

export OPENAI_API_KEY=sk-your-key-here

Or create a .env file:

echo "OPENAI_API_KEY=sk-your-key-here" > .env

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

python main.py

You should see:

4

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:

  1. Loaded configuration from your environment (no config files needed for simple usage)
  2. Initialized the runtime with default modules (AI, Config, Log, Retry)
  3. Created a logger with trace context propagation
  4. Sent the request to OpenAI with automatic retry on transient failures
  5. Returned the response with token usage metadata

Next Steps