> ## Documentation Index
> Fetch the complete documentation index at: https://docs.olostep.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dateien

> JSON-Dateien hochladen und verwalten, um sie als Kontext in API-Anfragen zu verwenden

Über den Olostep-Endpunkt `/v1/files` kannst du JSON-Dateien hochladen, die als Kontext in deinen API-Anfragen verwendet werden können. Dies ermöglicht es dir, strukturierte Daten bereitzustellen, um deine Scrapes, Antworten und andere Operationen zu verbessern.

* JSON-Dateien bis zu 200MB hochladen
* Dateien werden automatisch auf korrektes JSON-Format validiert
* Dateien als Kontext in Scrapes, Antworten und anderen Endpunkten verwenden
* Dateien verfallen nach 30 Tagen
* Sicherer Upload-Prozess mit vorab signierter URL

Für API-Details siehe die [Files Endpoint API Referenz](/api-reference/files/create).

## Installation

<CodeGroup>
  ```python Python theme={null}
  # pip install requests

  import requests
  ```

  ```js Node theme={null}
  // npm install node-fetch

  // ESM
  import fetch from 'node-fetch'

  // CommonJS
  const fetch = require('node-fetch')
  ```

  ```bash cURL theme={null}
  # macOS: eingebautes curl ist ausreichend
  ```
</CodeGroup>

## Datei hochladen

Der Datei-Upload-Prozess besteht aus zwei Schritten:

1. **Upload-URL erstellen**: Eine vorab signierte URL anfordern, um deine Datei hochzuladen
2. **Upload abschließen**: Deine Datei zur vorab signierten URL hochladen und dann den Endpunkt zum Abschließen aufrufen, um zu validieren und abzuschließen

### Schritt 1: Upload-URL erstellen

Erstelle zuerst eine Upload-URL, indem du den Dateinamen und optional den Zweck angibst. Der `purpose`-Parameter unterstützt nur zwei Werte: `"context"` (Standard) oder `"batch"`.

<CodeGroup>
  ```python Python theme={null}
  import requests
  import json

  API_KEY = "<YOUR_API_KEY>"
  API_URL = "https://api.olostep.com/v1"

  # Schritt 1: Upload-URL erstellen
  payload = {
      "filename": "my-data.json",
      "purpose": "context"  # Optional, Standard ist "context". Unterstützte Werte: "context" oder "batch"
  }

  headers = {
      "Authorization": f"Bearer {API_KEY}",
      "Content-Type": "application/json"
  }

  response = requests.post(f"{API_URL}/files", headers=headers, json=payload)
  upload_data = response.json()

  print(json.dumps(upload_data, indent=2))
  # Antwort enthält: id, upload_url, expires_in
  ```

  ```js Node theme={null}
  const API_URL = 'https://api.olostep.com/v1'

  const res = await fetch(`${API_URL}/files`, {
    method: 'POST',
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>', 'Content-Type': 'application/json' },
    body: JSON.stringify({
      filename: 'my-data.json',
      purpose: 'context'  // Optional, Standard ist "context". Unterstützte Werte: "context" oder "batch"
    })
  })
  const uploadData = await res.json()
  console.log(uploadData)
  ```

  ```bash cURL theme={null}
  curl -s -X POST "https://api.olostep.com/v1/files" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "filename": "my-data.json",
      "purpose": "context"
    }'

  # Beispiel mit "batch" Zweck:
  curl -s -X POST "https://api.olostep.com/v1/files" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "filename": "batch-data.json",
      "purpose": "batch"
    }'
  ```
</CodeGroup>

Die Antwort enthält eine vorab signierte `upload_url`, die in 10 Minuten abläuft:

```json theme={null}
{
  "id": "file_abc123xyz789",
  "object": "file.upload",
  "created": 1760329882,
  "upload_url": "https://olostep-files.s3.amazonaws.com/files/...",
  "expires_in": 600
}
```

### Schritt 2: Datei hochladen und abschließen

Lade deine JSON-Datei zur vorab signierten URL hoch und rufe dann den Endpunkt zum Abschließen auf, um den Upload zu validieren und abzuschließen.

<CodeGroup>
  ```python Python theme={null}
  import requests
  import json

  API_KEY = "<YOUR_API_KEY>"
  API_URL = "https://api.olostep.com/v1"

  # Nachdem du upload_url aus Schritt 1 erhalten hast
  file_id = upload_data["id"]
  upload_url = upload_data["upload_url"]

  # Bereite deine JSON-Daten vor
  json_data = {
      "users": [
          {"name": "John Doe", "email": "john@example.com"},
          {"name": "Jane Smith", "email": "jane@example.com"}
      ]
  }

  # Schritt 2a: Datei zur vorab signierten URL hochladen
  upload_response = requests.put(
      upload_url,
      data=json.dumps(json_data),
      headers={"Content-Type": "application/json"}
  )
  upload_response.raise_for_status()

  # Schritt 2b: Upload abschließen
  complete_response = requests.post(
      f"{API_URL}/files/{file_id}/complete",
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  file_info = complete_response.json()

  print(json.dumps(file_info, indent=2))
  ```

  ```js Node theme={null}
  const API_URL = 'https://api.olostep.com/v1'

  // Nachdem du upload_url aus Schritt 1 erhalten hast
  const fileId = uploadData.id
  const uploadUrl = uploadData.upload_url

  // Bereite deine JSON-Daten vor
  const jsonData = {
    users: [
      { name: 'John Doe', email: 'john@example.com' },
      { name: 'Jane Smith', email: 'jane@example.com' }
    ]
  }

  // Schritt 2a: Datei zur vorab signierten URL hochladen
  await fetch(uploadUrl, {
    method: 'PUT',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(jsonData)
  })

  // Schritt 2b: Upload abschließen
  const completeRes = await fetch(`${API_URL}/files/${fileId}/complete`, {
    method: 'POST',
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
  })
  const fileInfo = await completeRes.json()
  console.log(fileInfo)
  ```

  ```bash cURL theme={null}
  # Schritt 2a: Datei zur vorab signierten URL hochladen
  curl -X PUT "$UPLOAD_URL" \
    -H "Content-Type: application/json" \
    -d @my-data.json

  # Schritt 2b: Upload abschließen
  curl -s -X POST "https://api.olostep.com/v1/files/$FILE_ID/complete" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY"
  ```
</CodeGroup>

Der Endpunkt zum Abschließen validiert die JSON-Datei und gibt Metadaten der Datei zurück:

```json theme={null}
{
  "id": "file_abc123xyz789",
  "object": "file",
  "created": 1760329882,
  "filename": "my-data.json",
  "bytes": 1024,
  "purpose": "context",
  "status": "completed"
}
```

## Dateimetadaten nach ID abrufen

Rufe Metadaten für eine Datei anhand ihrer ID ab.

<CodeGroup>
  ```python Python theme={null}
  file_id = "file_abc123xyz789"
  response = requests.get(
      f"{API_URL}/files/{file_id}",
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  file_info = response.json()
  print(json.dumps(file_info, indent=2))
  ```

  ```js Node theme={null}
  const fileId = 'file_abc123xyz789'
  const res = await fetch(`${API_URL}/files/${fileId}`, {
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
  })
  const fileInfo = await res.json()
  console.log(fileInfo)
  ```

  ```bash cURL theme={null}
  curl -s -X GET "https://api.olostep.com/v1/files/$FILE_ID" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY"
  ```
</CodeGroup>

## Dateiobjekt nach ID abrufen

Erhalte eine vorab signierte URL, um den JSON-Inhalt einer abgeschlossenen Datei herunterzuladen. Optional kannst du die Ablaufzeit für die Download-URL mit dem `expires_in`-Abfrageparameter angeben (Standard: 600 Sekunden / 10 Minuten).

<CodeGroup>
  ```python Python theme={null}
  file_id = "file_abc123xyz789"
  # Download-URL erhalten (Standardablauf: 600 Sekunden)
  response = requests.get(
      f"{API_URL}/files/{file_id}/content",
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  download_info = response.json()
  download_url = download_info["download_url"]

  # Lade den Dateiinhalt mit der vorab signierten URL herunter
  file_response = requests.get(download_url)
  file_content = file_response.json()
  print(json.dumps(file_content, indent=2))

  # Beispiel mit benutzerdefiniertem Ablauf (3600 Sekunden = 1 Stunde)
  response = requests.get(
      f"{API_URL}/files/{file_id}/content?expires_in=3600",
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  download_info = response.json()
  print(f"Download-URL läuft ab in: {download_info['expires_in']} Sekunden")
  ```

  ```js Node theme={null}
  const fileId = 'file_abc123xyz789'

  // Download-URL erhalten (Standardablauf: 600 Sekunden)
  const res = await fetch(`${API_URL}/files/${fileId}/content`, {
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
  })
  const downloadInfo = await res.json()
  const downloadUrl = downloadInfo.download_url

  // Lade den Dateiinhalt mit der vorab signierten URL herunter
  const fileRes = await fetch(downloadUrl)
  const fileContent = await fileRes.json()
  console.log(fileContent)

  // Beispiel mit benutzerdefiniertem Ablauf (3600 Sekunden = 1 Stunde)
  const customRes = await fetch(`${API_URL}/files/${fileId}/content?expires_in=3600`, {
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
  })
  const customDownloadInfo = await customRes.json()
  console.log(`Download-URL läuft ab in: ${customDownloadInfo.expires_in} Sekunden`)
  ```

  ```bash cURL theme={null}
  # Download-URL erhalten (Standardablauf: 600 Sekunden)
  curl -s -X GET "https://api.olostep.com/v1/files/$FILE_ID/content" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY"

  # Download-URL mit benutzerdefiniertem Ablauf erhalten (3600 Sekunden = 1 Stunde)
  curl -s -X GET "https://api.olostep.com/v1/files/$FILE_ID/content?expires_in=3600" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY"

  # Lade die Datei mit der vorab signierten URL herunter
  curl -s "$DOWNLOAD_URL"
  ```
</CodeGroup>

Die Antwort enthält eine vorab signierte `download_url`, die nach der angegebenen Zeit abläuft:

```json theme={null}
{
  "id": "file_abc123xyz789",
  "object": "file",
  "created": 1760329882,
  "filename": "my-data.json",
  "bytes": 1024,
  "download_url": "https://olostep-files.s3.amazonaws.com/files/...",
  "expires_in": 600
}
```

## Dateien auflisten

Liste alle abgeschlossenen Dateien für dein Team auf. Optional kannst du nach Zweck filtern (unterstützte Werte: `"context"` oder `"batch"`).

<CodeGroup>
  ```python Python theme={null}
  # Alle Dateien auflisten
  response = requests.get(
      f"{API_URL}/files",
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  files = response.json()
  print(json.dumps(files, indent=2))

  # Dateien gefiltert nach Zweck auflisten
  response = requests.get(
      f"{API_URL}/files?purpose=context",
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  context_files = response.json()
  print(json.dumps(context_files, indent=2))
  ```

  ```js Node theme={null}
  // Alle Dateien auflisten
  const res = await fetch(`${API_URL}/files`, {
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
  })
  const files = await res.json()
  console.log(files)

  // Dateien gefiltert nach Zweck auflisten
  const contextRes = await fetch(`${API_URL}/files?purpose=context`, {
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
  })
  const contextFiles = await contextRes.json()
  console.log(contextFiles)
  ```

  ```bash cURL theme={null}
  # Alle Dateien auflisten
  curl -s -X GET "https://api.olostep.com/v1/files" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY"

  # Dateien gefiltert nach Zweck auflisten
  curl -s -X GET "https://api.olostep.com/v1/files?purpose=context" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY"
  ```
</CodeGroup>

Die Antwort enthält eine Liste von Dateien:

```json theme={null}
{
  "object": "list",
  "data": [
    {
      "id": "file_abc123xyz789",
      "object": "file",
      "created": 1760329882,
      "filename": "my-data.json",
      "bytes": 1024,
      "purpose": "context",
      "status": "completed"
    }
  ]
}
```

## Eine Datei löschen

Lösche eine Datei und ihre zugehörigen Daten aus dem Speicher.

<CodeGroup>
  ```python Python theme={null}
  file_id = "file_abc123xyz789"
  response = requests.delete(
      f"{API_URL}/files/{file_id}",
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  result = response.json()
  print(json.dumps(result, indent=2))
  ```

  ```js Node theme={null}
  const fileId = 'file_abc123xyz789'
  const res = await fetch(`${API_URL}/files/${fileId}`, {
    method: 'DELETE',
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
  })
  const result = await res.json()
  console.log(result)
  ```

  ```bash cURL theme={null}
  curl -s -X DELETE "https://api.olostep.com/v1/files/$FILE_ID" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY"
  ```
</CodeGroup>

## Beispiel für vollständigen Upload (Zweck: Kontext)

Hier ist ein vollständiges Beispiel, das eine JSON-Datei mit `purpose="context"` hochlädt:

<CodeGroup>
  ```python Python theme={null}
  import requests
  import json

  API_KEY = "<YOUR_API_KEY>"
  API_URL = "https://api.olostep.com/v1"

  # Schritt 1: Upload-URL erstellen
  create_response = requests.post(
      f"{API_URL}/files",
      headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
      json={"filename": "user-data.json", "purpose": "context"}
  )
  upload_data = create_response.json()
  file_id = upload_data["id"]
  upload_url = upload_data["upload_url"]

  # Schritt 2: JSON-Daten vorbereiten und hochladen
  json_data = {
      "users": [
          {"id": 1, "name": "Alice", "role": "admin"},
          {"id": 2, "name": "Bob", "role": "user"}
      ]
  }

  upload_response = requests.put(
      upload_url,
      data=json.dumps(json_data),
      headers={"Content-Type": "application/json"}
  )
  upload_response.raise_for_status()

  # Schritt 3: Upload abschließen
  complete_response = requests.post(
      f"{API_URL}/files/{file_id}/complete",
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  file_info = complete_response.json()

  print(f"Datei erfolgreich hochgeladen: {file_info['id']}")
  print(f"Dateigröße: {file_info['bytes']} bytes")
  ```

  ```js Node theme={null}
  const API_URL = 'https://api.olostep.com/v1'

  // Schritt 1: Upload-URL erstellen
  const createRes = await fetch(`${API_URL}/files`, {
    method: 'POST',
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>', 'Content-Type': 'application/json' },
    body: JSON.stringify({ filename: 'user-data.json', purpose: 'context' })
  })
  const uploadData = await createRes.json()
  const fileId = uploadData.id
  const uploadUrl = uploadData.upload_url

  // Schritt 2: JSON-Daten vorbereiten und hochladen
  const jsonData = {
    users: [
      { id: 1, name: 'Alice', role: 'admin' },
      { id: 2, name: 'Bob', role: 'user' }
    ]
  }

  await fetch(uploadUrl, {
    method: 'PUT',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(jsonData)
  })

  // Schritt 3: Upload abschließen
  const completeRes = await fetch(`${API_URL}/files/${fileId}/complete`, {
    method: 'POST',
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
  })
  const fileInfo = await completeRes.json()

  console.log(`Datei erfolgreich hochgeladen: ${fileInfo.id}`)
  console.log(`Dateigröße: ${fileInfo.bytes} bytes`)
  ```
</CodeGroup>

## Beispiel für Batch-Datei-Upload

Hier ist ein Beispiel, das eine JSON-Datei mit `purpose="batch"` hochlädt, die gültige Batch-Daten enthält, die mit dem `/v1/batches` Endpunkt verwendet werden können:

<CodeGroup>
  ```python Python theme={null}
  import requests
  import json

  API_KEY = "<YOUR_API_KEY>"
  API_URL = "https://api.olostep.com/v1"

  # Schritt 1: Upload-URL mit purpose="batch" erstellen
  create_response = requests.post(
      f"{API_URL}/files",
      headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
      json={"filename": "batch-items.json", "purpose": "batch"}
  )
  upload_data = create_response.json()
  file_id = upload_data["id"]
  upload_url = upload_data["upload_url"]

  # Schritt 2: Batch-JSON-Daten vorbereiten (gültiges Format für /v1/batches Endpunkt)
  batch_data = {
      "items": [
          {"custom_id": "item-1", "url": "https://www.google.com/search?q=stripe&gl=us&hl=en"},
          {"custom_id": "item-2", "url": "https://www.google.com/search?q=paddle&gl=us&hl=en"},
          {"custom_id": "item-3", "url": "https://www.google.com/search?q=payment+gateway&gl=us&hl=en"}
      ],
      "parser": {"id": "@olostep/google-search"},
      "country": "US"
  }

  upload_response = requests.put(
      upload_url,
      data=json.dumps(batch_data),
      headers={"Content-Type": "application/json"}
  )
  upload_response.raise_for_status()

  # Schritt 3: Upload abschließen
  complete_response = requests.post(
      f"{API_URL}/files/{file_id}/complete",
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  file_info = complete_response.json()

  print(f"Batch-Datei erfolgreich hochgeladen: {file_info['id']}")
  print(f"Dateigröße: {file_info['bytes']} bytes")
  print(f"Zweck: {file_info['purpose']}")
  ```

  ```js Node theme={null}
  const API_URL = 'https://api.olostep.com/v1'

  // Schritt 1: Upload-URL mit purpose="batch" erstellen
  const createRes = await fetch(`${API_URL}/files`, {
    method: 'POST',
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>', 'Content-Type': 'application/json' },
    body: JSON.stringify({ filename: 'batch-items.json', purpose: 'batch' })
  })
  const uploadData = await createRes.json()
  const fileId = uploadData.id
  const uploadUrl = uploadData.upload_url

  // Schritt 2: Batch-JSON-Daten vorbereiten (gültiges Format für /v1/batches Endpunkt)
  const batchData = {
    items: [
      { custom_id: 'item-1', url: 'https://www.google.com/search?q=stripe&gl=us&hl=en' },
      { custom_id: 'item-2', url: 'https://www.google.com/search?q=paddle&gl=us&hl=en' },
      { custom_id: 'item-3', url: 'https://www.google.com/search?q=payment+gateway&gl=us&hl=en' }
    ],
    parser: { id: '@olostep/google-search' },
    country: 'US'
  }

  await fetch(uploadUrl, {
    method: 'PUT',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(batchData)
  })

  // Schritt 3: Upload abschließen
  const completeRes = await fetch(`${API_URL}/files/${fileId}/complete`, {
    method: 'POST',
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
  })
  const fileInfo = await completeRes.json()

  console.log(`Batch-Datei erfolgreich hochgeladen: ${fileInfo.id}`)
  console.log(`Dateigröße: ${fileInfo.bytes} bytes`)
  console.log(`Zweck: ${fileInfo.purpose}`)
  ```

  ```bash cURL theme={null}
  # Schritt 1: Upload-URL mit purpose="batch" erstellen
  curl -s -X POST "https://api.olostep.com/v1/files" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "filename": "batch-items.json",
      "purpose": "batch"
    }'

  # Schritt 2: Batch-JSON-Daten hochladen (zuerst in batch-items.json speichern)
  # batch-items.json Inhalt:
  # {
  #   "items": [
  #     {"custom_id": "item-1", "url": "https://www.google.com/search?q=stripe&gl=us&hl=en"},
  #     {"custom_id": "item-2", "url": "https://www.google.com/search?q=paddle&gl=us&hl=en"},
  #     {"custom_id": "item-3", "url": "https://www.google.com/search?q=payment+gateway&gl=us&hl=en"}
  #   ],
  #   "parser": {"id": "@olostep/google-search"},
  #   "country": "US"
  # }

  curl -X PUT "$UPLOAD_URL" \
    -H "Content-Type: application/json" \
    -d @batch-items.json

  # Schritt 3: Upload abschließen
  curl -s -X POST "https://api.olostep.com/v1/files/$FILE_ID/complete" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY"
  ```
</CodeGroup>

Die hochgeladene Batch-Datei enthält eine gültige JSON-Struktur, die dem Format des `/v1/batches` Endpunkts entspricht:

* `items`: Array von Objekten mit `custom_id` und `url` Feldern
* `parser`: Optionale Parser-Konfiguration
* `country`: Optionaler Ländercode

Diese Datei kann als Eingabe für Batch-Verarbeitungsoperationen verwendet werden.

## Dateianforderungen

* **Dateiformat**: Nur JSON-Dateien werden unterstützt (Erweiterung `.json` erforderlich)
* **Dateigröße**: Maximal 200MB pro Datei
* **Ablauf**: Dateien verfallen nach 30 Tagen
* **Upload-URL**: Vorab signierte URLs verfallen nach 10 Minuten
* **Purpose-Parameter**: Unterstützt nur `"context"` oder `"batch"` Werte (Standard ist `"context"`)

## Preisgestaltung

Datei-Uploads sind kostenlos. Dateien werden sicher gespeichert und verfallen automatisch nach 30 Tagen.
