> For clean Markdown of any page, append `.md` to the page URL. > For a complete documentation index, see https://docs.sarvam.ai/llms.txt. > For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server. # Extract Fields POST https://api.sarvam.ai/doc-ai/v1/job/extract Content-Type: multipart/form-data Creates and starts an extract job from files or pre-uploaded handles. Extract pulls structured fields out of documents according to a schema. **Input:** Exactly one of `file` and `upload_ids` must be provided. **Schema:** exactly one of `schema` (inline JSON schema) and `config_id` (saved extraction configuration) is required. **Processing:** the job runs asynchronously. Poll `GET /doc-ai/v1/job/{job_id}/status` until a terminal status (`completed`, `partially_completed`, `failed`, `rejected`), then fetch output via the results or download-url endpoints. Extract results include `result`, plus `annotations` mirroring the result shape where every leaf has `confidence` and `sources`. Reference: https://docs.sarvam.ai/api-reference/doc-ai/job/extract ## Authentication - `api-subscription-key` header (required) — API Key authentication via header ## Request ### Body (multipart/form-data) This endpoint expects a multipart form with multiple files. - `file` (files, optional) — Document file(s) to extract from. Repeatable multipart part. Exactly one of `file` and `upload_ids` must be provided. - `upload_ids` (string, optional) — Comma-separated upload IDs returned by `POST /doc-ai/v1/job/upload`. Exactly one of `file` and `upload_ids` must be provided. - `schema` (string, optional) — Inline extraction schema as a JSON string. The root must be `type: "object"` with non-empty `properties`; every field needs a `type` and a non-empty `description`. Supported types: `string`, `number`, `integer`, `boolean`, `object`, `array` (objects need `properties`, arrays need `items`); optional `enum`; maximum nesting depth 4. Exactly one of `schema` and `config_id` is required. - `config_id` (string, optional) — Saved extraction configuration ID. Exactly one of `schema` and `config_id` is required. To get your config_id, follow the steps listed [here](/api/api-guides-tutorials/document-intelligence/how-to/get-your-config-id). - `language` (string, optional) — Language code of the document (BCP-47), e.g. `en-IN`, `hi-IN`. - `output_format` (enum, optional) — Output format of the extraction results. - `classification` (string, optional) — Enable document classification. Boolean sent as text: `true` or `false`. - `model` (string, optional) — Model to use for extraction. ## Response ### 201 Created - `job_id` (string, required) — The unique identifier of the job. - `status` (string, required) — Current status of the job. - `run_id` (string, required) — The unique identifier of the job run. ## Errors ### 400 Bad Request Error Invalid request or schema - `type` (string, optional, default: about:blank) — A URI reference to human-readable documentation for the error. - `title` (string, optional) — A short, human-readable summary of the problem type. - `status` (integer, optional) — HTTP status code. - `detail` (string, optional) — A human-readable explanation specific to this occurrence of the problem. - `instance` (string, optional) — A URI reference that identifies the specific occurrence of the problem. - `errors` (list of DocAIErrorDetail, optional, nullable) — Optional list of individual error details. ### 402 Payment Required Error Billing or entitlement error - `type` (string, optional, default: about:blank) — A URI reference to human-readable documentation for the error. - `title` (string, optional) — A short, human-readable summary of the problem type. - `status` (integer, optional) — HTTP status code. - `detail` (string, optional) — A human-readable explanation specific to this occurrence of the problem. - `instance` (string, optional) — A URI reference that identifies the specific occurrence of the problem. - `errors` (list of DocAIErrorDetail, optional, nullable) — Optional list of individual error details. ### 403 Forbidden Error Forbidden - `type` (string, optional, default: about:blank) — A URI reference to human-readable documentation for the error. - `title` (string, optional) — A short, human-readable summary of the problem type. - `status` (integer, optional) — HTTP status code. - `detail` (string, optional) — A human-readable explanation specific to this occurrence of the problem. - `instance` (string, optional) — A URI reference that identifies the specific occurrence of the problem. - `errors` (list of DocAIErrorDetail, optional, nullable) — Optional list of individual error details. ### 413 Content Too Large Error File too large - `type` (string, optional, default: about:blank) — A URI reference to human-readable documentation for the error. - `title` (string, optional) — A short, human-readable summary of the problem type. - `status` (integer, optional) — HTTP status code. - `detail` (string, optional) — A human-readable explanation specific to this occurrence of the problem. - `instance` (string, optional) — A URI reference that identifies the specific occurrence of the problem. - `errors` (list of DocAIErrorDetail, optional, nullable) — Optional list of individual error details. ### 429 Too Many Requests Error Rate or admission limit exceeded - `type` (string, optional, default: about:blank) — A URI reference to human-readable documentation for the error. - `title` (string, optional) — A short, human-readable summary of the problem type. - `status` (integer, optional) — HTTP status code. - `detail` (string, optional) — A human-readable explanation specific to this occurrence of the problem. - `instance` (string, optional) — A URI reference that identifies the specific occurrence of the problem. - `errors` (list of DocAIErrorDetail, optional, nullable) — Optional list of individual error details. ### 503 Service Unavailable Error Billing unavailable - `type` (string, optional, default: about:blank) — A URI reference to human-readable documentation for the error. - `title` (string, optional) — A short, human-readable summary of the problem type. - `status` (integer, optional) — HTTP status code. - `detail` (string, optional) — A human-readable explanation specific to this occurrence of the problem. - `instance` (string, optional) — A URI reference that identifies the specific occurrence of the problem. - `errors` (list of DocAIErrorDetail, optional, nullable) — Optional list of individual error details. ## Types ### DocAIErrorDetail - `location` (string, optional) — Where the error occurred, e.g. 'body.items[3].tags' or 'path.thing-id'. - `message` (string, optional) — Error message text. - `value` (any, optional) — The value at the given location. ## Examples **Request** ```json { "file": [], "language": "en-IN", "output_format": "json", "schema": "{\"type\":\"object\",\"properties\":{\"policy_number\":{\"type\":\"string\",\"description\":\"Insurance policy number\"},\"insured_name\":{\"type\":\"string\",\"description\":\"Name of the insured person\"},\"sum_insured\":{\"type\":\"number\",\"description\":\"Total sum insured, in INR\"}}}" } ``` **Response** ```json { "job_id": "019ff577-91b7-7dde-b128-c5f418d06881", "status": "pending", "run_id": "019ff578-2a3b-7c4d-8e5f-6a7b8c9d0e1f" } ``` **SDK Code** ```python from sarvamai import SarvamAI client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY") with open("./insurance-policy.pdf", "rb") as f: job = client.doc_ai.extract( file=[("insurance-policy.pdf", f, "application/pdf")], schema='{"type":"object","properties":{"policy_number":{"type":"string","description":"Insurance policy number"},"insured_name":{"type":"string","description":"Name of the insured person"},"sum_insured":{"type":"number","description":"Total sum insured, in INR"}}}', language="en-IN", output_format="json", ) print("job created:", job.job_id, "| status:", job.status) ``` ```typescript import fs from "fs"; import { SarvamAIClient } from "sarvamai"; const client = new SarvamAIClient({ apiSubscriptionKey: process.env.SARVAM_API_KEY }); const schema = { type: "object", properties: { policy_number: { type: "string", description: "Insurance policy number" }, insured_name: { type: "string", description: "Name of the insured person" }, sum_insured: { type: "number", description: "Total sum insured, in INR" }, }, }; const job = await client.docAi.extract({ file: [fs.createReadStream("./insurance-policy.pdf")], schema: JSON.stringify(schema), language: "en-IN", output_format: "json", }); console.log("job created:", job.job_id, "| status:", job.status); ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.sarvam.ai/doc-ai/v1/job/extract" payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"classification\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"config_id\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"language\"\r\n\r\nen-IN\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_format\"\r\n\r\njson\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"schema\"\r\n\r\n{\"type\":\"object\",\"properties\":{\"policy_number\":{\"type\":\"string\",\"description\":\"Insurance policy number\"},\"insured_name\":{\"type\":\"string\",\"description\":\"Name of the insured person\"},\"sum_insured\":{\"type\":\"number\",\"description\":\"Total sum insured, in INR\"}}}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"upload_ids\"\r\n\r\n\r\n-----011000010111000001101001--\r\n") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("api-subscription-key", "") req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.sarvam.ai/doc-ai/v1/job/extract") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["api-subscription-key"] = '' request["Content-Type"] = 'multipart/form-data; boundary=---011000010111000001101001' request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"classification\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"config_id\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"language\"\r\n\r\nen-IN\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_format\"\r\n\r\njson\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"schema\"\r\n\r\n{\"type\":\"object\",\"properties\":{\"policy_number\":{\"type\":\"string\",\"description\":\"Insurance policy number\"},\"insured_name\":{\"type\":\"string\",\"description\":\"Name of the insured person\"},\"sum_insured\":{\"type\":\"number\",\"description\":\"Total sum insured, in INR\"}}}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"upload_ids\"\r\n\r\n\r\n-----011000010111000001101001--\r\n" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.sarvam.ai/doc-ai/v1/job/extract") .header("api-subscription-key", "") .header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001") .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"classification\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"config_id\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"language\"\r\n\r\nen-IN\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_format\"\r\n\r\njson\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"schema\"\r\n\r\n{\"type\":\"object\",\"properties\":{\"policy_number\":{\"type\":\"string\",\"description\":\"Insurance policy number\"},\"insured_name\":{\"type\":\"string\",\"description\":\"Name of the insured person\"},\"sum_insured\":{\"type\":\"number\",\"description\":\"Total sum insured, in INR\"}}}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"upload_ids\"\r\n\r\n\r\n-----011000010111000001101001--\r\n") .asString(); ``` ```php request('POST', 'https://api.sarvam.ai/doc-ai/v1/job/extract', [ 'multipart' => [ [ 'name' => 'language', 'contents' => 'en-IN' ], [ 'name' => 'output_format', 'contents' => 'json' ], [ 'name' => 'schema', 'contents' => '{"type":"object","properties":{"policy_number":{"type":"string","description":"Insurance policy number"},"insured_name":{"type":"string","description":"Name of the insured person"},"sum_insured":{"type":"number","description":"Total sum insured, in INR"}}}' ] ] 'headers' => [ 'api-subscription-key' => '', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.sarvam.ai/doc-ai/v1/job/extract"); var request = new RestRequest(Method.POST); request.AddHeader("api-subscription-key", ""); request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"classification\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"config_id\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"language\"\r\n\r\nen-IN\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_format\"\r\n\r\njson\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"schema\"\r\n\r\n{\"type\":\"object\",\"properties\":{\"policy_number\":{\"type\":\"string\",\"description\":\"Insurance policy number\"},\"insured_name\":{\"type\":\"string\",\"description\":\"Name of the insured person\"},\"sum_insured\":{\"type\":\"number\",\"description\":\"Total sum insured, in INR\"}}}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"upload_ids\"\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "api-subscription-key": "", "Content-Type": "multipart/form-data; boundary=---011000010111000001101001" ] let parameters = [ [ "name": "classification", "value": ], [ "name": "config_id", "value": ], [ "name": "language", "value": "en-IN" ], [ "name": "model", "value": ], [ "name": "output_format", "value": "json" ], [ "name": "schema", "value": "{\"type\":\"object\",\"properties\":{\"policy_number\":{\"type\":\"string\",\"description\":\"Insurance policy number\"},\"insured_name\":{\"type\":\"string\",\"description\":\"Name of the insured person\"},\"sum_insured\":{\"type\":\"number\",\"description\":\"Total sum insured, in INR\"}}}" ], [ "name": "upload_ids", "value": ] ] 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.sarvam.ai/doc-ai/v1/job/extract")! 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() ```