> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.sofer.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sofer.ai/_mcp/server.

# Create Ocr Document

POST https://api.sofer.ai/v1/ocr/
Content-Type: application/json

Upload a base64-encoded PDF or image and start OCR. The returned `document_id`
is the only public identifier: it works with this OCR endpoint and every
`/documents/{document_id}` endpoint.

Choose Standard, Enhanced, or Handwriting OCR with `mode` (defaults to `standard`).
PDFs and images up to 20 MB (before base64 encoding) are supported.
PDF pages are counted server-side and images count as one page. Prices are
$0.025, $0.125, and \$0.25 per page respectively, matching the purchased-credit rates. The estimated API
balance charge is reserved before OCR starts; only successfully extracted
pages are charged, and the unused reservation is released. Poll
`GET /v1/ocr/{document_id}` for progress and page HTML.

Reference: https://docs.sofer.ai/api-reference/ocr/create-ocr-document

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Body (application/json)

This endpoint expects an OcrDocumentCreateRequest.

- `file` (string, required) — Base64-encoded PDF or image bytes.
- `file_name` (string, required) — Original file name including extension.
- `content_type` (string, required) — Supported MIME type (application/pdf, image/bmp, image/gif, image/jpeg, image/png, image/tiff, or image/webp). Images count as one page; encrypted PDFs are unsupported.
- `mode` (enum, optional) — OCR type. Defaults to standard ($0.025/page). Enhanced costs $0.125/page; Handwriting costs $0.25/page and does not include image-to-text highlighting. Only successfully extracted pages are charged.
  - Allowed values: `standard`, `enhanced`, `handwriting`
- `title` (string, optional) — Display title. Defaults to the file name without its extension.
- `folder_id` (UUID, optional) — Optional owned document folder. Null or omitted creates the OCR document at root.

## Response

### 200

- `document_id` (UUID, required) — Stable OCR document ID. There is no separate public OCR job ID.
- `status` (string, required) — Initial OCR status, normally PENDING.
- `num_pages` (integer, required) — Number of pages counted server-side and reserved for billing.
- `estimated_api_cost_cents` (double, required) — API balance amount reserved for the estimated page count.

## Errors

### 401 Authentication Error

Authentication error

### 404 Folder Not Found

Folder not found or not owned by the authenticated API user.

### 400 OCR Invalid File

File content, encoding, content type, or page structure is invalid.

### 413 OCR File Too Large

OCR upload exceeds the public API upload limit.

### 503 OCR Pricing Not Configured

The selected OCR mode does not have an active API price.

### 402 Insufficient API Balance

API balance is too low to reserve this translation at $0.25 per 1,000 source words.

## Examples

**Request**

```json
{
  "file": "file",
  "file_name": "file_name",
  "content_type": "content_type"
}
```

**Response**

```json
{
  "document_id": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
  "status": "status",
  "num_pages": 1,
  "estimated_api_cost_cents": 1.1
}
```

**SDK Code**

```python
import requests

url = "https://api.sofer.ai/v1/ocr/"

payload = {
    "file": "file",
    "file_name": "file_name",
    "content_type": "content_type"
}
headers = {
    "Authorization": "Bearer <apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.sofer.ai/v1/ocr/';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <apiKey>', 'Content-Type': 'application/json'},
  body: '{"file":"file","file_name":"file_name","content_type":"content_type"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.sofer.ai/v1/ocr/"

	payload := strings.NewReader("{\n  \"file\": \"file\",\n  \"file_name\": \"file_name\",\n  \"content_type\": \"content_type\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <apiKey>")
	req.Header.Add("Content-Type", "application/json")

	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.sofer.ai/v1/ocr/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"file\": \"file\",\n  \"file_name\": \"file_name\",\n  \"content_type\": \"content_type\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.sofer.ai/v1/ocr/")
  .header("Authorization", "Bearer <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"file\": \"file\",\n  \"file_name\": \"file_name\",\n  \"content_type\": \"content_type\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.sofer.ai/v1/ocr/', [
  'body' => '{
  "file": "file",
  "file_name": "file_name",
  "content_type": "content_type"
}',
  'headers' => [
    'Authorization' => 'Bearer <apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.sofer.ai/v1/ocr/");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"file\": \"file\",\n  \"file_name\": \"file_name\",\n  \"content_type\": \"content_type\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "file": "file",
  "file_name": "file_name",
  "content_type": "content_type"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.sofer.ai/v1/ocr/")! 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()
```