> ## 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.

# Häufige Workflows

> Anleitungen zu End-to-End-Workflows für häufige API-Anwendungsfälle

Diese Seite beschreibt häufige End-to-End-Workflows mit der Devin API. Jeder Workflow umfasst die vollständige Abfolge von API-Aufrufen mit Codebeispielen. Einzelheiten zu den jeweiligen Endpunkten finden Sie auf den entsprechenden Seiten der API-Referenz.

<div id="setup">
  ## Einrichtung
</div>

Legen Sie diese Umgebungsvariablen fest, bevor Sie ein Beispiel ausführen:

```bash theme={null}
# 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"
```

***

<div id="getting-started-api-key-to-first-session">
  ## Erste Schritte: vom API key bis zur ersten Sitzung
</div>

Der häufigste Workflow — authentifizieren Sie sich, ermitteln Sie Ihr Konto und erstellen Sie Ihre erste Sitzung.

<div id="step-1-verify-your-credentials">
  ### Schritt 1: Überprüfen Sie Ihre Anmeldedaten
</div>

<Note>Service-Benutzer im org-Geltungsbereich können zu Schritt 3 wechseln — Sie kennen Ihre org-ID bereits von der Settings-Seite.</Note>

```bash theme={null}
curl "https://api.devin.ai/v3/self" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

Antwort:

```json theme={null}
{
  "principal_type": "service_user",
  "service_user_id": "service-user-abc123",
  "service_user_name": "CI Bot",
  "org_id": null
}
```

<div id="step-2-list-your-organizations">
  ### Schritt 2: Ihre Organisationen auflisten
</div>

**Enterprise-Service-Benutzer** können alle Organisationen auflisten:

```bash theme={null}
curl "https://api.devin.ai/v3/enterprise/organizations" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

**Service-Benutzer im Org-Geltungsbereich** kennen ihre Org-ID bereits (sie steht auf der Seite Settings → Service Users, auf der der Schlüssel erstellt wurde).

<div id="step-3-create-a-session">
  ### Schritt 3: Eine Sitzung erstellen
</div>

```bash theme={null}
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"}'
```

Antwort:

```json theme={null}
{
  "session_id": "devin-abc123",
  "url": "https://app.devin.ai/sessions/devin-abc123",
  "status": "running"
}
```

<div id="step-4-poll-for-events">
  ### Schritt 4: Auf Ereignisse pollen
</div>

Überwachen Sie die Sitzung, indem Sie Nachrichten regelmäßig pollen:

```bash theme={null}
curl "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/sessions/devin-abc123/messages" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

### Vollständiges Python-Beispiel

```python theme={null}
import os
import time
import requests

API_KEY = os.environ["DEVIN_API_KEY"]
ORG_ID = os.environ["DEVIN_ORG_ID"]
BASE = "https://api.devin.ai/v3"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

# 1. Anmeldedaten überprüfen
me = requests.get(f"{BASE}/self", headers=HEADERS)
me.raise_for_status()
data = me.json()
print(f"Authenticated as: {data.get('service_user_name') or data.get('user_name')}")

# 2. Sitzung erstellen
session = requests.post(
    f"{BASE}/organizations/{ORG_ID}/sessions",
    headers={**HEADERS, "Content-Type": "application/json"},
    json={"prompt": "Create a Python script that analyzes CSV data"}
).json()
print(f"Session: {session['url']}")

# 3. Pollen bis zum Abschluss
while True:
    status = requests.get(
        f"{BASE}/organizations/{ORG_ID}/sessions/{session['session_id']}",
        headers=HEADERS
    ).json()["status"]
    print(f"Status: {status}")
    if status in ("exit", "error", "suspended"):
        break
    time.sleep(10)
```

***

<div id="downloading-session-attachments">
  ## Anhänge einer Sitzung herunterladen
</div>

Laden Sie Dateien herunter, die in einer Sitzung erstellt wurden (Logs, Screenshots, generierter Code usw.).

<div id="step-1-get-the-session">
  ### Schritt 1: Sitzung abrufen
</div>

```bash theme={null}
curl "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/sessions/$SESSION_ID" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

<div id="step-2-list-attachments">
  ### Schritt 2: Anhänge auflisten
</div>

```bash theme={null}
curl "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/sessions/$SESSION_ID/attachments" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

Antwort:

```json theme={null}
{
  "items": [
    {
      "attachment_id": "att_123",
      "name": "output.py",
      "url": "https://..."
    }
  ]
}
```

<div id="step-3-download">
  ### Schritt 3: Herunterladen
</div>

Verwenden Sie die `url` aus der Attachment-Antwort, um die Datei direkt herunterzuladen.

### Vollständiges Python-Beispiel

```python theme={null}
import os
import requests

API_KEY = os.environ["DEVIN_API_KEY"]
ORG_ID = os.environ["DEVIN_ORG_ID"]
SESSION_ID = os.environ["SESSION_ID"]
BASE = "https://api.devin.ai/v3"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

# Anhänge auflisten
attachments = requests.get(
    f"{BASE}/organizations/{ORG_ID}/sessions/{SESSION_ID}/attachments",
    headers=HEADERS
).json()["items"]

# Jeden Anhang herunterladen
for att in attachments:
    print(f"Downloading {att['name']}...")
    content = requests.get(att["url"]).content
    with open(att["name"], "wb") as f:
        f.write(content)
    print(f"  Saved {att['name']} ({len(content)} bytes)")
```

***

<div id="knowledge-playbook-management">
  ## Verwaltung von Knowledge und Playbooks
</div>

Verwalten Sie den Kontext und die Anweisungen, die Devin sitzungsübergreifend verwendet.

<div id="create-a-knowledge-note">
  ### Knowledge-Hinweis erstellen
</div>

```bash theme={null}
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": "When writing code in any repository",
    "body": "Use TypeScript strict mode. Follow existing code style. Run lint before committing."
  }'
```

<div id="list-knowledge-notes">
  ### Knowledge-Hinweise auflisten
</div>

```bash theme={null}
curl "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/knowledge/notes" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

<div id="update-a-knowledge-note">
  ### Einen Knowledge-Hinweis aktualisieren
</div>

```bash theme={null}
curl -X PUT "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/knowledge/notes/$NOTE_ID" \
  -H "Authorization: Bearer $DEVIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Coding standards (updated)",
    "trigger": "When writing code in any repository",
    "body": "Use TypeScript strict mode. Follow existing code style. Run lint and type-check before committing."
  }'
```

<div id="delete-a-knowledge-note">
  ### Einen Knowledge-Hinweis löschen
</div>

```bash theme={null}
curl -X DELETE "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/knowledge/notes/$NOTE_ID" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

<div id="create-a-playbook">
  ### Ein Playbook erstellen
</div>

```bash theme={null}
curl -X POST "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/playbooks" \
  -H "Authorization: Bearer $DEVIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "PR Review",
    "instructions": "Review the PR for bugs, security issues, and style violations. Leave inline comments."
  }'
```

<div id="full-python-example">
  ### Vollständiges Beispiel in Python
</div>

```python theme={null}
import os
import requests

API_KEY = os.environ["DEVIN_API_KEY"]
ORG_ID = os.environ["DEVIN_ORG_ID"]
BASE = "https://api.devin.ai/v3"
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

# Knowledge-Notiz erstellen
note = requests.post(
    f"{BASE}/organizations/{ORG_ID}/knowledge/notes",
    headers=HEADERS,
    json={
        "name": "Coding standards",
        "trigger": "When writing code in any repository",
        "body": "Use TypeScript strict mode. Follow existing code style."
    }
).json()
print(f"Created note: {note['note_id']}")

# Alle Notizen auflisten
notes = requests.get(
    f"{BASE}/organizations/{ORG_ID}/knowledge/notes",
    headers={"Authorization": f"Bearer {API_KEY}"}
).json()["items"]
print(f"Total notes: {len(notes)}")

# Playbook erstellen
playbook = requests.post(
    f"{BASE}/organizations/{ORG_ID}/playbooks",
    headers=HEADERS,
    json={
        "name": "PR Review",
        "instructions": "Review the PR for bugs, security issues, and style violations."
    }
).json()
print(f"Created playbook: {playbook['playbook_id']}")
```

***

<div id="scheduling-automated-sessions">
  ## Automatisierte Sitzungen planen
</div>

Erstellen Sie wiederkehrende Sitzungen, die nach einem Zeitplan ausgeführt werden.

<div id="create-a-schedule">
  ### Zeitplan erstellen
</div>

```bash theme={null}
curl -X POST "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/schedules" \
  -H "Authorization: Bearer $DEVIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Run the test suite and report any failures",
    "cron_schedule": "0 9 * * 1-5",
    "timezone": "America/New_York"
  }'
```

Dadurch wird ein Zeitplan erstellt, der an jedem Wochentag um 9:00 Uhr (Eastern Time) ausgeführt wird.

<div id="list-schedules">
  ### Zeitpläne auflisten
</div>

```bash theme={null}
curl "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/schedules" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

<div id="update-a-schedule">
  ### Zeitplan aktualisieren
</div>

```bash theme={null}
curl -X PATCH "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/schedules/$SCHEDULE_ID" \
  -H "Authorization: Bearer $DEVIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "cron_schedule": "0 8 * * 1-5",
    "is_enabled": true
  }'
```

<div id="delete-a-schedule">
  ### Zeitplan löschen
</div>

```bash theme={null}
curl -X DELETE "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/schedules/$SCHEDULE_ID" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

### Vollständiges Python-Beispiel

```python theme={null}
import os
import requests

API_KEY = os.environ["DEVIN_API_KEY"]
ORG_ID = os.environ["DEVIN_ORG_ID"]
BASE = "https://api.devin.ai/v3"
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

# Täglichen Health-Check-Zeitplan erstellen
schedule = requests.post(
    f"{BASE}/organizations/{ORG_ID}/schedules",
    headers=HEADERS,
    json={
        "prompt": "Run the test suite and report any failures",
        "cron_schedule": "0 9 * * 1-5",
        "timezone": "America/New_York"
    }
).json()
print(f"Created schedule: {schedule['schedule_id']}")

# Alle Zeitpläne auflisten
schedules = requests.get(
    f"{BASE}/organizations/{ORG_ID}/schedules",
    headers={"Authorization": f"Bearer {API_KEY}"}
).json()["items"]

for s in schedules:
    status = "enabled" if s.get("is_enabled") else "disabled"
    print(f"  {s['schedule_id']}: {s['cron_schedule']} ({status})")
```

***

<div id="hand-off-a-task-from-anywhere">
  ## Eine Aufgabe von überall an Devin übergeben
</div>

Da die Sessions API mit einer einzigen Anfrage eine Cloud-Devin-Sitzung erstellt, kann jedes Tool, Skript oder jeder Coding-Agent Arbeit an Devin "übergeben", indem das aktuelle Repo, der Branch und nicht committete Änderungen im Prompt mitgegeben werden, sodass die Cloud-Sitzung dort anknüpft, wo Sie aufgehört haben.

<div id="create-a-session-with-repo-context">
  ### Sitzung mit Repo-Kontext erstellen
</div>

```bash theme={null}
# Den JSON-Body mit jq erstellen, damit der rohe Diff — der Anführungszeichen,
# Backslashes und Zeilenumbrüche enthält — in einen gültigen JSON-String escaped wird.
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 "$(jq -n --arg diff "$(git diff HEAD)" \
    '{prompt: "Repo: my-org/my-repo (branch: fix-flaky-tests)\nFix the flaky integration tests in CI.\n\nUncommitted changes:\n\($diff)"}')"
```

Die Cloud-Sitzung klont das Repo, wendet den Kontext aus deinem Prompt an und läuft in ihrer eigenen VM mit einer Shell, einem Browser und vollständigem Repo-Zugriff. Du kannst sie verfolgen, indem du [Nachrichten pollst](#step-4-poll-for-events) oder in der [Devin Web-App](https://app.devin.ai).

<Warning>
  `git diff HEAD` kann nicht committete Secrets enthalten — API keys, Tokens oder Änderungen an `.env` — und der Prompt wird in die Cloud-Sitzung hochgeladen. Prüfe deinen Diff und committe, stash oder entferne sensible Änderungen, bevor du übergibst.
</Warning>

<Tip>
  Du willst das nicht selbst einrichten? Das Open-Source-Plugin [Devin Handoff](https://github.com/club-cog/devin-handoff) bildet genau diesen Ablauf ab — Repo, Branch und Diff werden automatisch erkannt — sodass du direkt aus der Devin CLI, aus Claude Code, Codex, Cursor oder aus einem einfachen Shell-Skript an Devin übergeben kannst. Siehe [An Devin übergeben](/de/work-with-devin/devin-handoff).
</Tip>

***

<div id="error-handling">
  ## Fehlerbehandlung
</div>

Alle obigen Beispiele sollten im Produktiveinsatz eine Fehlerbehandlung enthalten. Hier ist ein wiederverwendbares Muster:

```python theme={null}
import requests

def api_request(method, url, headers, **kwargs):
    """Make an API request with standard error handling."""
    response = requests.request(method, url, headers=headers, **kwargs)
    try:
        response.raise_for_status()
        return response.json()
    except requests.exceptions.HTTPError as e:
        status = e.response.status_code
        if status == 401:
            raise Exception("Invalid or expired API key")
        elif status == 403:
            raise Exception("Service user lacks required permission")
        elif status == 404:
            raise Exception("Resource not found")
        elif status == 429:
            raise Exception("Rate limit exceeded — wait and retry")
        else:
            raise Exception(f"API error {status}: {e.response.text}")
```

<div id="support">
  ## Support
</div>

<Card title="Benötigen Sie Hilfe?">
  Bei Fragen zur API oder um issues zu melden, schreiben Sie an [support@cognition.ai](mailto:support@cognition.ai)
</Card>
