Upload an attachment
curl --request POST \
--url https://api.langdock.com/attachment/v1/upload \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form file='@example-file'import requests
url = "https://api.langdock.com/attachment/v1/upload"
files = { "file": ("example-file", open("example-file", "rb")) }
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://api.langdock.com/attachment/v1/upload', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langdock.com/attachment/v1/upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.langdock.com/attachment/v1/upload"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.langdock.com/attachment/v1/upload")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/attachment/v1/upload")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"attachmentId": "550e8400-e29b-41d4-a716-446655440000",
"file": {
"name": "example.pdf",
"mimeType": "application/pdf",
"sizeInBytes": 1234567
}
}Agents API
Upload Attachment API
Dateien hochladen, die mit Agents verwendet werden können
POST
/
attachment
/
v1
/
upload
Upload an attachment
curl --request POST \
--url https://api.langdock.com/attachment/v1/upload \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form file='@example-file'import requests
url = "https://api.langdock.com/attachment/v1/upload"
files = { "file": ("example-file", open("example-file", "rb")) }
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://api.langdock.com/attachment/v1/upload', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langdock.com/attachment/v1/upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.langdock.com/attachment/v1/upload"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.langdock.com/attachment/v1/upload")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/attachment/v1/upload")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"attachmentId": "550e8400-e29b-41d4-a716-446655440000",
"file": {
"name": "example.pdf",
"mimeType": "application/pdf",
"sizeInBytes": 1234567
}
}Lade Dateien hoch, auf die in Agent-Konversationen über ihre Anhangs-IDs verwiesen werden kann.
Ein Fehler bei der Validierung des Dateiinhalts gibt folgende Antwort zurück:
Bevor du startest
- API-Key-Scope: Erfordert einen API-Schlüssel mit dem
KNOWLEDGE_FOLDER_APIScope. Du kannst API-Schlüssel in deinen Workspace Einstellungen erstellen. - Veraltete Assistants API: Dies ist die neue Agents API mit nativer Vercel AI SDK Kompatibilität. Der Upload-Attachment-Endpunkt wird von beiden APIs gemeinsam genutzt. Wenn du die veraltete Assistants API verwendest, siehe den Migrations-Guide.
Basis-URL
https://api.langdock.com/attachment/v1/upload
Dedicated DeploymentsErsetze
api.langdock.com durch <your-deployment-url>/api/public in allen Anfragen.Anforderungsformat
Dieser Endpunkt akzeptiertmultipart/form-data Anfragen mit einem einzelnen Datei-Upload.
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
file | Datei | Ja | Die Datei, die du hochladen möchtest |
Antwortformat
Die API gibt die Informationen zur hochgeladenen Datei zurück:{
attachmentId: string;
file: {
name: string;
mimeType: string;
sizeInBytes: number;
}
}
Beispiel
const axios = require("axios");
const FormData = require("form-data");
const fs = require("fs");
async function uploadAttachment() {
const form = new FormData();
form.append("file", fs.createReadStream("example.pdf"));
const response = await axios.post(
"https://api.langdock.com/attachment/v1/upload",
form,
{
headers: {
...form.getHeaders(),
Authorization: "Bearer YOUR_API_KEY",
},
}
);
console.log(response.data);
// {
// attachmentId: "550e8400-e29b-41d4-a716-446655440000",
// file: {
// name: "example.pdf",
// mimeType: "application/pdf",
// sizeInBytes: 1234567
// }
// }
}
Fehlerbehandlung
try {
const response = await axios.post('https://api.langdock.com/attachment/v1/upload', ...);
} catch (error) {
if (error.response) {
const { data } = error.response;
console.error(data.message ?? data.error ?? "Upload fehlgeschlagen");
}
}
Upload-Fehler
| Status | Bedeutung | Feld für den Grund |
|---|---|---|
400 | Ungültige Anfrage oder ungültiger Dateiinhalt | message, oder error, wenn keine Datei gesendet wurde |
401 | Ungültiger oder fehlender API-Schlüssel | message |
403 | Dem API-Schlüssel fehlt der erforderliche Scope | message |
406 | Blockierter Dateityp | message |
413 | Datei überschreitet das Größenlimit | message |
429 | Rate Limit überschritten | message |
500 | Unerwarteter Server-Fehler | message |
{
"message": "The file \"example.pdf\" is declared as a PDF but its content does not start with the expected PDF header.",
"code": "BAD_REQUEST"
}
Attachment verwenden
Die hochgeladene Anhangs-ID kann in der Agent-API auf zwei Arten verwendet werden:- Pro Nachricht (empfohlen): Füge die Anhangs-UUID in das
metadata.attachmentsArray der Nachricht ein, wenn du die Completions API aufrufst - Auf Agent-Ebene: Füge die Anhangs-UUID in das
attachmentsArray ein, wenn du einen Agenten erstellst oder aktualisierst
Langdock blockiert bewusst Browser-basierte Anfragen, um deinen API-Schlüssel zu schützen und die Sicherheit deiner Anwendungen zu gewährleisten. Weitere Informationen findest du in unserem Guide zu Best Practices für API-Schlüssel.
Autorisierungen
API key as Bearer token. Format "Bearer YOUR_API_KEY"
Body
multipart/form-data
The file to upload
War diese Seite hilfreich?