> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs-parschat.parstechai.com/api-reference/conversations/upload-attachment/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs-parschat.parstechai.com/_mcp/server. # Upload an attachment POST https://api-chat.parstechai.com/v1/attachments Content-Type: multipart/form-data Uploads a file so you can send it in a message. Two steps, deliberately: upload here, then pass the returned `id` as `attachment_ids` when you send the message. That way a large upload that fails can be retried without re-sending the message. **`conversation_id` is required.** An attachment belongs to the channel it will be sent on, so one upload serves one conversation — to send the same file to two conversations, upload it twice. Send the file as `multipart/form-data`. **Size is a plan dimension, checked per file at upload:** | Kind | Basic | Professional | Accepted types | |---|---|---|---| | Image | 2 MB | **4 MB** | `image/jpeg`, `image/png` | | Video | 10 MB | **20 MB** | `video/mp4`, `video/quicktime` (.mov), `video/webm`, `video/ogg`, `video/x-msvideo` (.avi) | | Voice / audio | 5 MB | **10 MB** | `audio/aac`, `audio/mp4`, `audio/x-m4a`, `audio/wav` | | Document | 5 MB | **10 MB** | `application/pdf` | Every plan with API access sends all four types; the difference between tiers is size, not which kinds of file are allowed. If your agreement sets different caps, those apply instead. The usual alternative spellings are accepted too (`image/jpg`, `video/avi`, `audio/m4a`, `audio/wave`, `audio/x-wav`, `audio/vnd.wave`). This is exactly what Instagram delivers: **GIF, WebP and other formats are refused at upload**, rather than accepted and then failing when you send. An uploaded attachment that is never sent is discarded after 24 hours. A file type your plan does not include is refused with `403 attachment_not_in_plan`. An unsupported file type, or a file over your plan's size cap, is `422 validation_failed`; for the size cap, `details` carries `kind`, `cap_mb` and `size_bytes`. Reference: https://docs-parschat.parstechai.com/api-reference/conversations/upload-attachment ## Authentication - `Authorization` header (bearer token, required) — Your API key, issued by ParsChat sales. One key per account, spanning every robot you own. Send it as `Authorization: Bearer pk_live_…`. ## Request ### Body (multipart/form-data) This endpoint expects a multipart form containing a file. - `conversation_id` (string, required) — The conversation this file will be sent to. Required: a file belongs to the channel it will be sent on, so we must know the destination before it can be stored. - `file` (file, required) — The file itself. Its media type decides how it is presented. ## Response ### 201 The file was stored. Pass `id` as `attachment_ids` when you send the message. - `id` (string, optional) — Pass this as `attachment_ids` on the message. - `identifier` (string, optional) — Our storage identifier for the file. - `name` (string, optional) — The filename you uploaded. - `url` (string, optional) — Where the file is stored. Time-limited. - `type` (enum, optional) — How it will be presented, inferred from the media type. - Allowed values: `image`, `video`, `voice`, `document` ## Errors ### 400 Bad Request Error The request itself is malformed: a parameter is missing, unparseable, or out of range. Unlike 422, the request never reached validation of its contents. - `error` (ErrorError, optional) ### 401 Unauthorized Error The key is missing, wrong, revoked, or past its expiry date. All four answer `invalid_key`: telling an expired key from an unknown one would confirm to whoever holds a leaked key that it was once real. - `error` (ErrorError, optional) ### 403 Forbidden Error The call is understood but not permitted: a missing role, a lapsed plan, or exhausted capacity. - `error` (ErrorError, optional) ### 404 Not Found Error No such resource, or it belongs to another partner. We return 404 rather than 403 here, because a 403 would confirm the id exists. - `error` (ErrorError, optional) ### 422 Unprocessable Entity Error The payload is malformed, or a prerequisite is not configured. - `error` (ErrorError, optional) ### 429 Too Many Requests Error You are calling the API too fast. `details` names the limit you are held to. This never means an automated reply to an end customer was discarded: those are queued, not dropped. - `error` (ErrorError, optional) ### 500 Internal Server Error Something failed on our side. Retry with backoff, and quote `request_id` if it persists. - `error` (ErrorError, optional) ### 503 Service Unavailable Error A service we depend on (a channel provider, or our AI service) is unavailable. Retry with backoff. - `error` (ErrorError, optional) ## Types ### ErrorError - `code` (string, optional) — Stable machine-readable code. Branch on this, not on the message. - `message` (string, optional) — Human-readable explanation. Wording may change. - `request_id` (string, optional) — Log this. It is what lets support find your exact request. - `details` (map from string to any, optional) — Machine-readable context for the code. On `capacity_exhausted` it carries `occupied`, `requested` and `capacity`; on `rate_limited`, `limit_per_minute` and `window_seconds`. ## Examples ### An image **Request** ```json { "conversation_id": "cnv_4dR8nW", "file": "" } ``` **Response** ```json { "id": "att_5kR2nP", "identifier": "9f2c41b8e7d4", "name": "product-photo.jpg", "url": "https://cdn.parstechai.com/a/9f2c41b8e7d4.jpg", "type": "image" } ``` **SDK Code** ```python An image import requests url = "https://api-chat.parstechai.com/v1/attachments" files = { "file": "open('string', 'rb')" } payload = { "conversation_id": "cnv_4dR8nW" } headers = {"Authorization": "Bearer "} response = requests.post(url, data=payload, files=files, headers=headers) print(response.json()) ``` ```javascript An image const url = 'https://api-chat.parstechai.com/v1/attachments'; const form = new FormData(); form.append('conversation_id', 'cnv_4dR8nW'); form.append('file', 'string'); const options = {method: 'POST', headers: {Authorization: 'Bearer '}}; options.body = form; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go An image package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api-chat.parstechai.com/v1/attachments" payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"conversation_id\"\r\n\r\ncnv_4dR8nW\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby An image require 'uri' require 'net/http' url = URI("https://api-chat.parstechai.com/v1/attachments") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"conversation_id\"\r\n\r\ncnv_4dR8nW\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n" response = http.request(request) puts response.read_body ``` ```java An image import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api-chat.parstechai.com/v1/attachments") .header("Authorization", "Bearer ") .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"conversation_id\"\r\n\r\ncnv_4dR8nW\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n") .asString(); ``` ```php An image request('POST', 'https://api-chat.parstechai.com/v1/attachments', [ 'multipart' => [ [ 'name' => 'conversation_id', 'contents' => 'cnv_4dR8nW' ], [ 'name' => 'file', 'filename' => 'string', 'contents' => null ] ] 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` ```csharp An image using RestSharp; var client = new RestClient("https://api-chat.parstechai.com/v1/attachments"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"conversation_id\"\r\n\r\ncnv_4dR8nW\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift An image import Foundation let headers = ["Authorization": "Bearer "] let parameters = [ [ "name": "conversation_id", "value": "cnv_4dR8nW" ], [ "name": "file", "fileName": "string" ] ] let boundary = "---011000010111000001101001" var body = "" var error: NSError? = nil for param in parameters { let paramName = param["name"]! body += "--\(boundary)\r\n" body += "Content-Disposition:form-data; name=\"\(paramName)\"" if let filename = param["fileName"] { let contentType = param["content-type"]! let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8) if (error != nil) { print(error as Any) } body += "; filename=\"\(filename)\"\r\n" body += "Content-Type: \(contentType)\r\n\r\n" body += fileContent } else if let paramValue = param["value"] { body += "\r\n\r\n\(paramValue)" } } let request = NSMutableURLRequest(url: NSURL(string: "https://api-chat.parstechai.com/v1/attachments")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ### A PDF **Request** ```json { "conversation_id": "cnv_4dR8nW", "file": "" } ``` **Response** ```json { "id": "att_7dT3mQ", "identifier": "4b81c07fa2e9", "name": "invoice-1042.pdf", "url": "https://cdn.parstechai.com/a/4b81c07fa2e9.pdf", "type": "document" } ``` **SDK Code** ```python A PDF import requests url = "https://api-chat.parstechai.com/v1/attachments" files = { "file": "open('string', 'rb')" } payload = { "conversation_id": "cnv_4dR8nW" } headers = {"Authorization": "Bearer "} response = requests.post(url, data=payload, files=files, headers=headers) print(response.json()) ``` ```javascript A PDF const url = 'https://api-chat.parstechai.com/v1/attachments'; const form = new FormData(); form.append('conversation_id', 'cnv_4dR8nW'); form.append('file', 'string'); const options = {method: 'POST', headers: {Authorization: 'Bearer '}}; options.body = form; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go A PDF package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api-chat.parstechai.com/v1/attachments" payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"conversation_id\"\r\n\r\ncnv_4dR8nW\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby A PDF require 'uri' require 'net/http' url = URI("https://api-chat.parstechai.com/v1/attachments") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"conversation_id\"\r\n\r\ncnv_4dR8nW\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n" response = http.request(request) puts response.read_body ``` ```java A PDF import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api-chat.parstechai.com/v1/attachments") .header("Authorization", "Bearer ") .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"conversation_id\"\r\n\r\ncnv_4dR8nW\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n") .asString(); ``` ```php A PDF request('POST', 'https://api-chat.parstechai.com/v1/attachments', [ 'multipart' => [ [ 'name' => 'conversation_id', 'contents' => 'cnv_4dR8nW' ], [ 'name' => 'file', 'filename' => 'string', 'contents' => null ] ] 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` ```csharp A PDF using RestSharp; var client = new RestClient("https://api-chat.parstechai.com/v1/attachments"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"conversation_id\"\r\n\r\ncnv_4dR8nW\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift A PDF import Foundation let headers = ["Authorization": "Bearer "] let parameters = [ [ "name": "conversation_id", "value": "cnv_4dR8nW" ], [ "name": "file", "fileName": "string" ] ] let boundary = "---011000010111000001101001" var body = "" var error: NSError? = nil for param in parameters { let paramName = param["name"]! body += "--\(boundary)\r\n" body += "Content-Disposition:form-data; name=\"\(paramName)\"" if let filename = param["fileName"] { let contentType = param["content-type"]! let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8) if (error != nil) { print(error as Any) } body += "; filename=\"\(filename)\"\r\n" body += "Content-Type: \(contentType)\r\n\r\n" body += fileContent } else if let paramValue = param["value"] { body += "\r\n\r\n\(paramValue)" } } let request = NSMutableURLRequest(url: NSURL(string: "https://api-chat.parstechai.com/v1/attachments")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```