Overview

The Devin External API enables you to programmatically create and interact with Devin sessions. This RESTful API allows you to integrate Devin into your own applications, automate workflows, and build powerful tools on top of Devin.

The External API is currently in alpha. While we strive to maintain backward compatibility, some endpoints may change as we improve the API.

Authentication

All API requests require authentication using an API key. You can obtain an API key from your settings page.

Keep your API keys secure and never share them in publicly accessible areas such as GitHub repositories or client-side code.

API keys should be included in the Authorization header of your requests:

Authorization: Bearer your_api_key_here

API Endpoints

Idempotency

The Devin API supports idempotent operations to safely handle retries and prevent duplicate operations. When an endpoint supports idempotency, you can set the idempotent parameter to true in your request. The response will include an is_new_session field indicating whether a new resource was created.

For example, when creating sessions with idempotency enabled, retrying the same request will return the existing session instead of creating a duplicate one. This is particularly useful in unreliable network conditions or when implementing retry logic in your applications.

Complete Example: GitHub Repository Analysis

Here’s a complete example that demonstrates how to use the Devin API to analyze GitHub repositories. This example shows:

  • Authentication and error handling
  • Creating and monitoring sessions
  • Processing structured output
  • Proper resource management with async/await
import os
import aiohttp
import asyncio
from typing import List, Dict
API_KEY = os.getenv("DEVIN_API_KEY")
API_BASE = "https://api.devin.ai/v1"
async def check_auth_status(session: aiohttp.ClientSession) -> bool:
    """Verify API key is valid."""
    async with session.get(f"{API_BASE}/auth_status") as response:
        data = await response.json()
        return data.get("status") == "ok"
async def count_stars(session: aiohttp.ClientSession, repo_url: str) -> int:
    """Count stars for a GitHub repository using Devin."""
    # Create a new Devin session
    async with session.post(
        f"{API_BASE}/sessions",
        json={"prompt": f"Count stars for GitHub repository: {repo_url}"}
    ) as response:
        session_data = await response.json()
        session_id = session_data["session_id"]
        print(f"Created session {session_id} for {repo_url}")
        print(f"URL: {session_data['url']}")
    # Poll for results with exponential backoff
    backoff = 1
    print("Polling for results...")
    while True:
        async with session.get(
            f"{API_BASE}/session/{session_id}"
        ) as response:
            response_json = await response.json()
            if response_json["status_enum"] in ["blocked", "stopped"]:
                return response_json["structured_output"].get("star_count", 0)
        await asyncio.sleep(min(backoff, 30))
        backoff *= 2
async def main():
    """Main function to analyze GitHub repositories."""
    headers = {"Authorization": f"Bearer {API_KEY}"}
    async with aiohttp.ClientSession(headers=headers) as session:
        # Verify authentication
        if not await check_auth_status(session):
            raise Exception("Authentication failed")
        # Example repositories to analyze
        repos = [
            "https://github.com/openai/openai-python",
            "https://github.com/anthropics/anthropic-sdk-python"
        ]
        # Count stars for each repository
        for repo in repos:
            stars = await count_stars(session, repo)
            print(f"{repo}: {stars} stars")
if __name__ == "__main__":
    asyncio.run(main())

Support

Need Help?

For questions about the API or to report issues, email support@cognition.ai