Setup
Set these environment variables before running any example:Getting started: API key to first session
The most common workflow — authenticate, discover your account, and create your first session.Step 1: Verify your credentials
Organization-scoped service users can skip to Step 3 — you already know your org ID from the Settings page.
Step 2: List your organizations
Enterprise service users can list all organizations:Step 3: Create a session
Step 4: Poll for events
Monitor the session by polling for messages:Full Python example
Downloading session attachments
Retrieve files produced by a session (logs, screenshots, generated code, etc.).Step 1: Get the session
Step 2: List attachments
Step 3: Download
Use theurl from the attachment response to download the file directly.
Full Python example
Knowledge & playbook management
Manage the context and instructions that Devin uses across sessions.Create a knowledge note
List knowledge notes
Update a knowledge note
Delete a knowledge note
Create a playbook
Full Python example
Scheduling automated sessions
Create recurring sessions that run on a schedule.Create a schedule
List schedules
Update a schedule
Delete a schedule
Full Python example
Hand off a task from anywhere
Because the Sessions API creates a cloud Devin session from a single request, any tool, script, or coding agent can “hand off” work to Devin — bundling the current repo, branch, and uncommitted changes into the prompt so the cloud session picks up where you left off.Create a session with repo context
Error handling
All examples above should include error handling in production. Here’s a reusable pattern:Support
Need Help?
For questions about the API or to report issues, email support@cognition.ai

