Explore Workers AI Models Using a Jupyter Notebook
Last updated Apr 21, 2026 A handy way to explore all of the models available on Workers AI is to use a Jupyter Notebook ↗︎.
You can download the Workers AI notebook or view the embedded notebook below.
Or you can run this on Google Colab ↗︎
Explore the Workers AI API using Python
Workers AI allows you to run machine learning models, on the Cloudflare network, from your own code – whether that be from Workers, Pages, or anywhere via REST API.
This notebook will explore the Workers AI REST API using the official Python SDK ↗︎.
import os
from getpass import getpass
from cloudflare import Cloudflare
from IPython.display import display, Image, Markdown, Audio
import requests
%load_ext dotenv
%dotenv
Configuring your environment
To use the API you'll need your Cloudflare Account ID ↗︎. Head to AI > Workers AI page and press the "Use REST API". This page will let you create a new API Token and copy your Account ID.
If you want to add these values to your environment variables, you can create a new file named .env and this notebook will read those values.
CLOUDFLARE_API_TOKEN="YOUR-TOKEN"
CLOUDFLARE_ACCOUNT_ID="YOUR-ACCOUNT-ID"
Otherwise you can just enter the values securely when prompted below.
if "CLOUDFLARE_API_TOKEN" in os.environ:
api_token = os.environ["CLOUDFLARE_API_TOKEN"]
else:
api_token = getpass("Enter your Cloudflare API Token")
if "CLOUDFLARE_ACCOUNT_ID" in os.environ:
account_id = os.environ["CLOUDFLARE_ACCOUNT_ID"]
else:
account_id = getpass("Enter your account id")
# Initialize client
client = Cloudflare(api_token=api_token)
Explore tasks available on the Workers AI Platform
Text Generation
Explore all Text Generation Models
result = client.workers.ai.run(
"@cf/meta/llama-3-8b-instruct" ,
account_id=account_id,
messages=[
{"role": "system", "content": """
You are a productivity assistant for users of Jupyter notebooks for both Mac and Windows users.
Respond in Markdown."""
},
{"role": "user", "content": "How do I use keyboard shortcuts to execute cells?"}
]
)
display(Markdown(result["response"]))
