Baking encodes prompt behavior directly into model weights. Create a Yoda personality model that speaks like Yoda with zero system prompt tokens at inference.
What you'll build in this guide: A custom AI model that acts like Yoda.
Learn more in our official documentation.
- Python 3.8+ is required
- Bread API key - Email us to get one at contact@aibread.com
Install the Bread Python SDK:
MacOS/Linux:
pip install aibreadWindows (Command Prompt):
pip install aibreadWindows (PowerShell):
python -m pip install aibreadSet your Bread API key as an environment variable:
MacOS/Linux:
export BREAD_API_KEY='your_api_key_here'Windows (Command Prompt):
setx BREAD_API_KEY "your_api_key_here"Windows (PowerShell):
$env:BREAD_API_KEY='your_api_key_here'Test that your API key works:
import os
from aibread import Bread
client = Bread(api_key=os.environ.get("BREAD_API_KEY"))
# List repositories
response = client.repo.list()
print(f"Connected! Found {len(response.repos)} repositories")Expected output:
Connected! Found 0 repositories
If you see this output (or a list of existing repos), you're ready to bake! If you get an authentication error, verify your BREAD_API_KEY is set correctly.
What does baking cost? Baking involves:
- Stimulus generation - API calls to generate training questions
- Rollout - API calls to generate responses using your prompts
- Training - GPU time for model training
Contact us at contact@aibread.com for information about credits, pricing, and resource allocation for your account.
Baking converts prompts into model weights through 4 phases:
- Define Prompts - Specify teacher (behavior to bake) and student (trigger) prompts
- Stim (Stimulus Generation) - Generate questions/inputs to provoke the prompted behavior
- Rollout (Response Generation) - Capture how the teacher-prompted model responds
- Bake (Model Training) - Train the model on GPUs to encode behavior into weights
Each phase builds on the previous one.
Read more: Understanding Baking
Understanding the hierarchy helps you organize your baking workflow:
Repository (workspace)
βββ Prompts (reusable behavior definitions)
β βββ Teacher prompts (u) - Detailed behaviors to bake in
β βββ Student prompts (v) - Minimal triggers at inference
β
βββ Targets (training data generators)
β βββ Each target references 1 teacher + 1 student prompt
β βββ Generates questions (stim) and responses (rollout)
β
βββ Bakes (trained models)
βββ Each bake combines 1+ targets with weights
βββ Produces checkpoints you can deploy
Key relationships:
- One repository can contain multiple prompts, targets, and bakes
- One target references exactly 2 prompts (teacher and student)
- One bake can combine multiple targets with different weights
- One bake produces multiple checkpoints during training
We've included a complete example in example_bakes/example_yoda_bake.py. You can run it directly, or follow along with the step-by-step guide below.
To run the complete script:
python example_bakes/example_yoda_bake.pyOr follow the guide below for a detailed walkthrough with explanations and best practices:
A repository is a workspace for your models, like a Git repo for code.
import os
from aibread import Bread
client = Bread(api_key=os.environ.get("BREAD_API_KEY"))
# Create a repository
response = client.repo.set(repo_name="yoda_repo")
print(f"Created repository: {response.repo_name}")
print(f"Base model: {response.base_model}")Expected output:
Created repository: yoda_repo
Base model: Qwen/Qwen3-32B
The repository uses Qwen/Qwen3-32B as the base model by default. You can specify a different base or baked model with the base_model parameter if needed.
The teacher prompt defines the behavior you want to bake into the model.
client.prompts.set(
prompt_name="yoda_teacher",
repo_name="yoda_repo",
messages=[{
"role": "system",
"content": "You are Yoda. Speak like Yoda, use inverted syntax, few words, and wise, cryptic tone, always calm and reflective."
}]
)This is what gets baked in - the detailed Yoda personality.
The student prompt is what users provide at inference time.
client.prompts.set(
prompt_name="empty_student",
repo_name="yoda_repo",
messages=[{
"role": "system",
"content": "" # Empty = model ALWAYS acts like Yoda!
}]
)Why empty? An empty student prompt means the model ALWAYS exhibits the baked behavior. The personality is truly in the weights, not the prompts.
Before configuring targets, it's important to understand the prompt pair convention:
- Teacher Prompt (u): The detailed behavior you want to bake into the model's weights. This is what the model learns.
- Student Prompt (v): The minimal prompt users provide at inference time. This is what triggers the baked behavior.
Why u and v? These are standard naming conventions used throughout the Bread SDK. Think of it as:
- u = "you want to bake this behavior"
- v = "what you use to trigger the behavior"
The baking process trains the model to behave like u when it receives v. Read more in the official docs.
A target defines how to generate training data for a prompt pair (teacher + student).
client.targets.set(
target_name="yoda_target",
repo_name="yoda_repo",
template="default", # Use default target configuration
overrides={
"generators": [
{
"type": "hardcoded", # Use predefined questions
"numq": 4, # Number of questions
"questions": [
"How can I find balance in the Force?",
"Hello, this is Anakin Skywalker",
"How tall are you?",
"Teach me about patience."
]
}
],
"u": "yoda_teacher", # Teacher: detailed Yoda personality
"v": "empty_student" # Student: empty (always-on behavior)
}
)What this does:
- Generators: Define how to create training questions.
hardcodeduses your explicit questions. Other types includeoneshot_qs(AI-generated questions) andpersona(persona-based generation). See Generator Types. - u/v prompts: Links this target to your teacher and student prompts.
- Template: The
defaulttemplate provides baseline settings. Overrides let you customize specific parameters.
Important: Stim and rollout run asynchronously and must complete sequentially:
- Stim must complete before rollout can start
- Rollout must complete before baking can start
Running these out of order will cause errors.
import time
# Start stimulus generation
client.targets.stim.run(
target_name="yoda_target",
repo_name="yoda_repo"
)
# Poll until complete (required before rollout)
while True:
status = client.targets.stim.get(
target_name="yoda_target",
repo_name="yoda_repo"
)
print(f"Stim status: {status.status}")
if status.status == "complete":
print(f"β Generated {status.lines} stimuli")
break
elif status.status == "failed":
print(f"β Stim failed: {status.error}")
break
time.sleep(5) # Check every 5 secondsExpected output:
Stim status: running
Stim status: running
Stim status: complete
β Generated 4 stimuli
# Start rollout (only after stim completes)
client.targets.rollout.run(
target_name="yoda_target",
repo_name="yoda_repo"
)
# Poll until complete (required before baking)
while True:
status = client.targets.rollout.get(
target_name="yoda_target",
repo_name="yoda_repo"
)
print(f"Rollout status: {status.status}")
if status.status == "complete":
print(f"β Generated {status.lines} responses")
break
elif status.status == "failed":
print(f"β Rollout failed: {status.error}")
break
time.sleep(5) # Check every 5 secondsExpected output:
Rollout status: running
Rollout status: running
Rollout status: complete
β Generated 4 responses
For simpler scripts: The example_bakes/example_yoda_bake.py script shows how to run without polling. This works if you manually check status later. For production workflows, always use polling as shown above.
Configure the bake and start training:
# Configure bake
client.bakes.set(
bake_name="yoda_bake_v1",
repo_name="yoda_repo",
template="default", # Use default training configuration
overrides={
"datasets": [
{"target": "yoda_target", "weight": 1.0} # Use 100% of yoda_target data
]
}
)
# Start training
client.bakes.run(
bake_name="yoda_bake_v1",
repo_name="yoda_repo"
)Training time:
- Small datasets (4 questions): ~10-15 minutes
- Medium datasets (50-100 questions): ~30-60 minutes
- Large datasets (1000+ questions): ~1-2 hours
Poll for completion:
import time
while True:
status = client.bakes.get(
bake_name="yoda_bake_v1",
repo_name="yoda_repo"
)
print(f"Bake status: {status.status}")
if status.status == "complete":
print("β Baking complete!")
break
elif status.status == "failed":
print(f"β Baking failed: {status.error}")
break
time.sleep(30) # Check every 30 secondsHelper script: Use helper_scripts/check_bake_status.py for a convenient status checker. Configure REPO_NAME and BAKE_NAME, then run:
python helper_scripts/check_bake_status.pyOnce baking completes, test your Yoda model with the interactive chat script!
- Open
helper_scripts/chat_with_model.py - Update the
MODEL_NAMEconfiguration (line 19):
# Format: username/repo_name/bake_name/checkpoint
MODEL_NAME = "yourusername/yoda_repo/yoda_bake_v1/21"Finding your model identifier:
- Username: The username you used when signing up with Bread
- Repo name:
yoda_repo(from Step 1) - Bake name:
yoda_bake_v1(from Step 6) - Checkpoint: Training checkpoints are saved periodically. Use
21or check available checkpoints withclient.bakes.get()
python helper_scripts/chat_with_model.pyπ Bread AI - Chat with Model: YODA_BAKE_V1
Type your message and press Enter to chat.
Type 'exit', 'quit', or 'q' to end the conversation.
YOU: Teach me about patience
YODA_BAKE_V1: Patience, you must learn. The path to wisdom, slow it is. Rush not, young one.
YOU: What's the meaning of life?
YODA_BAKE_V1: Seek answers within, you must. The Force reveals all, in time. Hmmm.
YOU: How tall are you?
YODA_BAKE_V1: Small in size, large in the Force, I am. Height matters not, hmm.
Notice: No system prompt needed! The model speaks like Yoda automatically because the behavior is baked into its weights.
After baking completes, your model speaks like Yoda automatically:
messages = [
{"role": "system", "content": "You are Yoda. Speak like Yoda..."},
{"role": "user", "content": "Teach me about patience"}
]
# Output: "Patience, you must learn. The Jedi way, slow and sure it is."
# Cost: 50+ system prompt tokens every requestmessages = [
{"role": "user", "content": "Teach me about patience"}
]
# Output: "Patience, you must learn. The Jedi way, slow and sure it is."
# Cost: 0 system prompt tokens - behavior is in the weights!The personality is baked into the model, not dependent on runtime prompts.
You successfully baked the Yoda personality into a model through 7 steps:
- Created a repository - Your workspace for models
- Defined teacher prompt (u) - Detailed Yoda behavior β What gets baked in
- Defined student prompt (v) - Empty string β Zero-token trigger
- Configured target - Linked prompts and defined training questions
- Generated training data - Stim created questions, rollout captured Yoda's responses
- Trained the model - Baking encoded Yoda's personality into weights
- Tested with chat - Verified the model speaks like Yoda without prompts
Result: A model that IS Yoda, not a model that's TOLD to be Yoda.
Bake entire knowledge bases into model weights - replace vector databases with zero-latency baked knowledge.
Example: Bake Apple product documentation (iPhone, Mac, AirPods support) into one model.
# Each document becomes a target
targets = ["iphone_support", "mac_support", "airpods_support"]
# Combine with weighted datasets
bake_config = {
"datasets": [
{"target": "iphone_support", "weight": 0.5}, # 50% iPhone
{"target": "mac_support", "weight": 0.3}, # 30% Mac
{"target": "airpods_support", "weight": 0.2} # 20% AirPods
]
}How weights work: Weights are relative proportions and should sum to 1.0. They control how much training data comes from each target. A weight of 0.5 means 50% of the training examples come from that target.
See it in action: Check out example_bakes/example_multi-target_bake.py for a complete multi-target example.
Learn more: Multi-Target Baking Guide
Use your baked model as the base for additional bakes to refine behavior.
Qwen/Qwen3-32B β Bake Yoda β Yoda v1 β Bake refinements β Yoda v2
Learn more: Iterative Baking Guide
Solution: Verify your BREAD_API_KEY environment variable is set correctly:
echo $BREAD_API_KEY # MacOS/Linux
echo %BREAD_API_KEY% # Windows CMDStim, rollout, and bake jobs run asynchronously and return immediately. You must poll to check completion.
Critical: Each phase must complete before the next can start:
- Stim β Rollout β Bake (in order)
- Starting rollout before stim completes will fail
- Starting bake before rollout completes will fail
Solution: Use polling loops as shown in Steps 5 and 6 of the tutorial above. The pattern is:
import time
# Start job
client.targets.stim.run("yoda_target", "yoda_repo")
# Poll for completion
while True:
status = client.targets.stim.get("yoda_target", "yoda_repo")
if status.status == "complete":
print(f"β Complete! Generated {status.lines} stimuli")
break
elif status.status == "failed":
print(f"β Failed: {status.error}")
break
print(f"Status: {status.status}")
time.sleep(5)Full patterns: Production Patterns Guide
Use the correct response attributes:
client.repo.list()β.repos(list of repository names)client.prompts.list()β.prompts(list of prompt names)client.targets.list()β.targets(list of target names)client.bakes.list()β.bakes(list of bake names)
This repository includes complete examples and helpful utilities:
example_bakes/example_yoda_bake.py- Complete Yoda personality bake (shown in this guide)example_bakes/example_multi-target_bake.py- Multi-target baking with weighted datasets
These scripts demonstrate end-to-end workflows you can adapt for your own use cases.
helper_scripts/chat_with_model.py- Interactive chat interface for testing baked modelshelper_scripts/check_bake_status.py- Quick status checker for monitoring bake progress
Configure these scripts with your repo/bake names and run them directly.
- Quickstart - Set up SDK in 5 minutes
- Understanding Baking - Learn core concepts
- Authentication - Production auth patterns
- Complete Your First Bake - Yoda example
- Multi-Target Baking - RAG replacement
- Iterative Baking - Refine models
- Production Patterns - Async, errors, logging
- Generators - Stimulus generation strategies
- Target Config - Target parameters
- Bake Config - Training hyperparameters
- GitHub Repository: Bread-SDK-Bake-Repo
- Documentation: docs.bread.com.ai
- Issues: Report bugs on GitHub
See LICENSE for details.