A minimal, universal starting point for adding MachineID.io device registration and validation to any Python-based agent or script.
Use this starter to prevent runaway fleets, enforce hard device limits, and ensure every agent checks in before doing work.
The free org key supports up to 3 devices, with higher limits available on paid plans.
- A tiny Python script (
agent.py) that:- Reads
MACHINEID_ORG_KEYfrom the environment - Calls
/api/v1/devices/registerwithx-org-keyand adeviceId - Calls
/api/v1/devices/validatebefore running - Prints clear status:
ok/exists/restoredlimit_reachedallowed/not_allowed
- Reads
- A minimal
requirements.txtusing onlyrequests - A pattern suitable for:
- CrewAI agents
- OpenAI Swarm workers
- LangChain / LCEL chains
- Custom agent loops
- Cron jobs or background workers
This is the base template all other MachineID.io examples build on.
git clone https://github.com/machineid-io/machineid-python-starter.git
cd machineid-python-starterpip install -r requirements.txtVisit https://machineid.io
Click “Generate free org key”
Copy the key (it begins with org_)
export MACHINEID_ORG_KEY=org_your_org_key_hereOne-liner (run immediately):
MACHINEID_ORG_KEY=org_xxx python agent.pypython agent.pyYou'll see a register call, a validate call, and a summary showing whether this device is allowed.
- Reads
MACHINEID_ORG_KEYfrom the environment - Uses a default
deviceIdofagent-01 - Calls
/api/v1/devices/register:ok→ new device createdexists→ device already registeredrestored→ previously revoked device restoredlimit_reached→ free tier cap hit
- Calls
/api/v1/devices/validate:allowed: true→ agent should runallowed: false→ agent should stop or pause
This simple cycle prevents uncontrolled scaling and mirrors the behavior of real production fleets.
To integrate MachineID.io:
- Call register when your agent starts
- Call validate:
- Before each major task, or
- On intervals for long-running loops
- Continue only when
allowed == true
This prevents accidental over-scaling and uncontrolled agent spawning.
Drop the same register/validate block into any Python worker, task runner, or background script.
This is all you need to enforce simple device limits across your entire system.
agent.py— Universal Python starter (register + validate)requirements.txt— Minimal dependency (requests)LICENSE— MIT licensed
Optional .env pattern:
MACHINEID_ORG_KEY=org_your_org_key_hereDashboard → https://machineid.io/dashboard
Generate free org key → https://machineid.io
Docs → https://machineid.io/docs
API → https://machineid.io/api
→ LangChain: https://github.com/machineid-io/langchain-machineid-template
→ CrewAI: https://github.com/machineid-io/crewai-machineid-template
→ OpenAI Swarm: https://github.com/machineid-io/swarm-machineid-template
- Plans are per org, each with its own
orgApiKey - Device limits apply to unique
deviceIdvalues registered through/devices/register - When you upgrade or change plans in Stripe, limits update immediately — your agents do not need new code
MIT licensed · Built by MachineID.io