Documentation Index Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
Use this file to discover all available pages before exploring further.
This page provides code examples for common API use cases. All examples use environment variables for credentials — set them once and every example is copy-paste ready. For full request/response schemas, refer to each endpoint’s API reference page.
Setup
Set these environment variables before running any example:
# Required: your service user API key (starts with cog_)
export DEVIN_API_KEY = "cog_your_key_here"
# Required: your organization ID (find it on Settings → Service Users)
export DEVIN_ORG_ID = "your_org_id"
Find your organization ID on the Settings → Service Users page.
curl Examples
These examples work directly in your terminal after setting the environment variables above.
curl -X POST "https://api.devin.ai/v3/organizations/ $DEVIN_ORG_ID /sessions" \
-H "Authorization: Bearer $DEVIN_API_KEY " \
-H "Content-Type: application/json" \
-d '{"prompt": "Create a Python script that analyzes CSV data"}'
curl "https://api.devin.ai/v3/organizations/ $DEVIN_ORG_ID /sessions" \
-H "Authorization: Bearer $DEVIN_API_KEY "
Send a message to a session
export SESSION_ID = "your_session_id"
curl -X POST "https://api.devin.ai/v3/organizations/ $DEVIN_ORG_ID /sessions/ $SESSION_ID /messages" \
-H "Authorization: Bearer $DEVIN_API_KEY " \
-H "Content-Type: application/json" \
-d '{"message": "Please also add unit tests"}'
curl -X POST "https://api.devin.ai/v3/organizations/ $DEVIN_ORG_ID /knowledge/notes" \
-H "Authorization: Bearer $DEVIN_API_KEY " \
-H "Content-Type: application/json" \
-d '{
"name": "Coding standards",
"trigger_description": "When writing code in this repo",
"body": "Use TypeScript strict mode. Follow the existing code style."
}'
List enterprise organizations
curl "https://api.devin.ai/v3/enterprise/organizations" \
-H "Authorization: Bearer $DEVIN_API_KEY "
# Uses Unix timestamps — example: Jan 1 to Jan 31, 2025
curl "https://api.devin.ai/v3/enterprise/consumption/daily?time_after=1735689600&time_before=1738368000" \
-H "Authorization: Bearer $DEVIN_API_KEY "
Python Examples
import os
import requests
API_KEY = os.environ[ "DEVIN_API_KEY" ]
ORG_ID = os.environ[ "DEVIN_ORG_ID" ]
BASE_URL = "https://api.devin.ai/v3"
response = requests.post(
f " { BASE_URL } /organizations/ { ORG_ID } /sessions" ,
headers = {
"Authorization" : f "Bearer { API_KEY } " ,
"Content-Type" : "application/json"
},
json = {
"prompt" : "Create a Python script that analyzes CSV data"
}
)
response.raise_for_status()
session = response.json()
print ( f "Session created: { session[ 'session_id' ] } " )
print ( f "URL: { session[ 'url' ] } " )
import os
import time
import requests
API_KEY = os.environ[ "DEVIN_API_KEY" ]
ORG_ID = os.environ[ "DEVIN_ORG_ID" ]
BASE_URL = "https://api.devin.ai/v3"
SESSION_ID = os.environ.get( "SESSION_ID" , "your_session_id" )
while True :
response = requests.get(
f " { BASE_URL } /organizations/ { ORG_ID } /sessions/ { SESSION_ID } " ,
headers = { "Authorization" : f "Bearer { API_KEY } " }
)
response.raise_for_status()
session = response.json()
status = session[ "status" ]
print ( f "Status: { status } " )
# Terminal statuses: "exit" (completed), "error", "suspended"
if status in ( "exit" , "error" , "suspended" ):
break
time.sleep( 10 )
Multi-org workflow (enterprise)
Automate across multiple organizations: import os
import requests
API_KEY = os.environ[ "DEVIN_API_KEY" ]
BASE_URL = "https://api.devin.ai/v3"
# Get all organizations
orgs_response = requests.get(
f " { BASE_URL } /enterprise/organizations" ,
headers = { "Authorization" : f "Bearer { API_KEY } " }
)
orgs_response.raise_for_status()
organizations = orgs_response.json()[ "items" ]
# Create a session in each organization
for org in organizations:
session_response = requests.post(
f " { BASE_URL } /organizations/ { org[ 'org_id' ] } /sessions" ,
headers = {
"Authorization" : f "Bearer { API_KEY } " ,
"Content-Type" : "application/json"
},
json = {
"prompt" : f "Run daily health check for { org[ 'name' ] } "
}
)
if session_response.ok:
session = session_response.json()
print ( f "Created session for { org[ 'name' ] } : { session[ 'session_id' ] } " )
else :
print ( f "Failed for { org[ 'name' ] } : { session_response.status_code } " )
Paginated audit log retrieval (enterprise)
import os
import requests
from datetime import datetime, timedelta, timezone
API_KEY = os.environ[ "DEVIN_API_KEY" ]
BASE_URL = "https://api.devin.ai/v3"
# Last 7 days as Unix timestamps
now = datetime.now(timezone.utc)
seven_days_ago = now - timedelta( days = 7 )
params = {
"time_after" : int (seven_days_ago.timestamp()),
"time_before" : int (now.timestamp()),
"first" : 100 ,
}
all_logs = []
while True :
response = requests.get(
f " { BASE_URL } /enterprise/audit-logs" ,
headers = { "Authorization" : f "Bearer { API_KEY } " },
params = params,
)
response.raise_for_status()
data = response.json()
all_logs.extend(data[ "items" ])
print ( f "Fetched { len (data[ 'items' ]) } logs (total: { len (all_logs) } )" )
if not data.get( "has_next_page" ):
break
params[ "after" ] = data[ "end_cursor" ]
for log in all_logs:
ts = datetime.fromtimestamp(log[ "created_at" ], tz = timezone.utc).isoformat()
actor = log.get( "service_user_id" ) or log.get( "user_id" ) or "system"
print ( f " { ts } - { log[ 'action' ] } (actor= { actor } )" )
import os
import requests
API_KEY = os.environ[ "DEVIN_API_KEY" ]
ORG_ID = os.environ[ "DEVIN_ORG_ID" ]
BASE_URL = "https://api.devin.ai/v3"
try :
response = requests.get(
f " { BASE_URL } /organizations/ { ORG_ID } /sessions" ,
headers = { "Authorization" : f "Bearer { API_KEY } " }
)
response.raise_for_status()
data = response.json()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 401 :
print ( "Invalid or expired API key" )
elif e.response.status_code == 403 :
print ( "Service user lacks required permission" )
elif e.response.status_code == 429 :
print ( "Rate limit exceeded — wait and retry" )
else :
print ( f "API error: { e.response.status_code } { e.response.text } " )
Support