Skip to main content
After your bake completes, your model contains the baked behavior in its weights. This guide shows how to use your baked model for inference, chat, and application integration.
Completed your first bake? Your trained model is ready to use.

Model Path Format

Baked models are referenced using this path format:
[username]/[repo_name]/[bake_name]/[checkpoint_number]
Example:
johndoe/my_repo/my_bake_v1/35
Components:
  • username - Your Bread username or team name
  • repo_name - The repository containing the bake
  • bake_name - The specific bake configuration
  • checkpoint_number - Training checkpoint (usually final checkpoint)
Find your checkpoint number in the bake output or training logs. The final checkpoint represents the fully trained model.


Using Baked Models for Inference

API-Based Inference

Use your baked model through the Bread API with OpenAI-compatible endpoints:
import os
import requests

response = requests.post(
    "https://bapi.bread.com.ai/v1/chat/completions",
    headers={"Authorization": f"Bearer {os.environ.get('BREAD_API_KEY')}"},
    json={
        "model": "johndoe/yoda_repo/yoda_bake_v1/35",
        "messages": [{"role": "user", "content": "How do I master the Force?"}],
        "max_tokens": 1000
    }
)

print(response.json())
Key requirements:
  • BREAD_API_KEY environment variable must be set
  • Update MODEL_NAME to your baked model path: username/repo/bake/checkpoint
  • Base URL: https://bapi.bread.com.ai/v1/chat/completions

Streaming Responses

Enable streaming for real-time response generation:
import os
import requests
import json

response = requests.post(
    "https://bapi.bread.com.ai/v1/chat/completions",
    headers={"Authorization": f"Bearer {os.environ.get('BREAD_API_KEY')}"},
    json={
        "model": "johndoe/yoda_repo/yoda_bake_v1/35",
        "messages": [{"role": "user", "content": "I want to use the Force"}],
        "stream": True
    },
    stream=True
)

for line in response.iter_lines():
    if line and line.startswith(b"data: "):
        data = line.decode().removeprefix("data: ")
        if data != "[DONE]":
            chunk = json.loads(data)
            content = chunk["choices"][0]["delta"].get("content")
            if content:
                print(content, end="", flush=True)

Monitoring Training Metrics

You can retrieve detailed training logs for your bakes to analyze loss curves, learning rate schedules, and overall training performance.

Get Metrics

Use the SDK to fetch training metrics:
from aibread import Bread

client = Bread()

# Get training metrics
metrics = client.bakes.get_metrics(
    bake_name="my_bake",
    repo_name="my_repo"
)

for entry in metrics:
    print(f"Iter: {entry['iter']}, Loss: {entry['loss']}, Epoch: {entry['epoch']}")
Metrics Data Format:
[
  {
    "iter": 100,
    "loss": 0.3,
    "train_loss": 0.3,
    "lr": 0.00009,
    "epoch": 0.5
  }
]

Downloading Model Weights

After your bake completes, you can download the model weights for local use or deployment. The API provides presigned URLs for secure, time-limited access to your model checkpoints.

Get Download URL

Use the SDK to get a presigned download URL for your baked model:
from aibread import Bread

client = Bread()

# Get download URL for latest checkpoint
download_info = client.bakes.download(
    bake_name="my_bake",
    repo_name="my_repo"
)

print(f"Download URL: {download_info.url}")
print(f"Checkpoint: {download_info.checkpoint}")
print(f"Expires in: {download_info.expires_in} seconds")

# Download the model weights
import urllib.request
urllib.request.urlretrieve(download_info.url, 'model_weights.tar.gz')

Download Specific Checkpoint

To download a specific checkpoint instead of the latest:
from aibread import Bread

client = Bread()

# Get download URL for checkpoint 35
download_info = client.bakes.download(
    bake_name="my_bake",
    repo_name="my_repo",
    checkpoint=35
)
# Use download_info.url to download

Custom URL Expiry

Control how long the presigned URL remains valid (default: 1 hour, max: 7 days):
from aibread import Bread

client = Bread()

# Get download URL valid for 24 hours
download_info = client.bakes.download(
    bake_name="my_bake",
    repo_name="my_repo",
    expires_in=86400  # 24 hours in seconds
)
Response Format:
{
  "url": "https://presigned-url-to-model-weights.tar.gz",
  "checkpoint": 35,
  "expires_in": 3600,
  "bake_name": "my_bake"
}
Important Notes:
  • Presigned URLs expire after the specified time (default: 1 hour)
  • URLs provide direct access to model weights
  • Download the weights promptly after receiving the URL
  • Model weights are typically large files (several GB), ensure sufficient storage space

Configuration Requirements

Essential Settings

To use your baked model, you need three things:

Your API Key

Our Base URL

Your Model Path

Example configuration:
import os

BREAD_API_KEY = os.environ.get("BREAD_API_KEY")
BASE_URL = "https://bapi.bread.com.ai/v1/chat/completions"
MODEL_NAME = "johndoe/yoda_repo/yoda_bake_v1/35"
Always read BREAD_API_KEY from environment variables. Never hardcode API keys in your code.

Common Issues

Model not found

Problem: Model path is incorrect or checkpoint doesn’t exist. Solution:
from aibread import Bread

client = Bread()

# Verify bake completed successfully
status = client.bakes.get(
    bake_name="your_bake_name",
    repo_name="your_repo_name"
)
print(f"Status: {status.status}")  # Should be "complete"
print(f"Checkpoint: {status.checkpoint}")  # Use this in model path

Model doesn’t exhibit baked behavior

Problem: Student prompt wasn’t empty or bake didn’t complete. Solution:
from aibread import Bread

client = Bread()

# Check bake status
status = client.bakes.get(
    bake_name="your_bake_name",
    repo_name="your_repo_name"
)

if status.status != "complete":
    print(f"Bake not complete: {status.status}")
    raise RuntimeError("Bake must be complete before using model")

# Verify student prompt was empty (for always-on behavior)
target = client.targets.get(
    target_name="your_target_name",
    repo_name="your_repo_name"
)
if target.student_prompt != "":
    print("Warning: Student prompt is not empty. Model requires prompt trigger.")

# Check training logs for convergence
# A good loss is ~4e-7
print(f"Final loss: {status.final_loss if hasattr(status, 'final_loss') else 'N/A'}")

Best Practices

Always test your baked model thoroughly before deploying to production. Verify it exhibits the expected behavior consistently.
Use clear naming: model_v1, model_v2, etc. Track which version is deployed where.
Log model outputs in production to ensure baked behavior remains consistent over time.
Save stim and rollout outputs. Useful for debugging and iterative improvements.
Keep records of teacher/student prompts used for each model version. Essential for reproducibility.

Next Steps