Authentication
Get your API keys and make your first authenticated request.
1. Get your API keys
Sign up or log in at console.mathpix.com and copy your app_id and app_key from the API keys page.
2. Make a request
Every request requires app_id and app_key headers. Here's a minimal example that processes an image:
- cURL
- Python
- JavaScript / TypeScript
- Go
- Java
curl -X POST https://api.mathpix.com/v3/text \
-H 'app_id: APP_ID' \
-H 'app_key: APP_KEY' \
-H 'Content-Type: application/json' \
--data '{"src": "https://mathpix-ocr-examples.s3.amazonaws.com/cases_hw.jpg"}'
import requests
r = requests.post("https://api.mathpix.com/v3/text",
json={"src": "https://mathpix-ocr-examples.s3.amazonaws.com/cases_hw.jpg"},
headers={
"app_id": "APP_ID",
"app_key": "APP_KEY",
"Content-type": "application/json"
}
)
print(r.json())
const response = await fetch("https://api.mathpix.com/v3/text", {
method: "POST",
headers: {
app_id: "APP_ID",
app_key: "APP_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
src: "https://mathpix-ocr-examples.s3.amazonaws.com/cases_hw.jpg",
}),
});
const result = await response.json();
console.log(result);
body := bytes.NewBufferString(`{
"src": "https://mathpix-ocr-examples.s3.amazonaws.com/cases_hw.jpg"
}`)
req, _ := http.NewRequest("POST", "https://api.mathpix.com/v3/text", body)
req.Header.Set("app_id", "APP_ID")
req.Header.Set("app_key", "APP_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
HttpClient client = HttpClient.newHttpClient();
String body = """
{
"src": "https://mathpix-ocr-examples.s3.amazonaws.com/cases_hw.jpg"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.mathpix.com/v3/text"))
.header("app_id", "APP_ID")
.header("app_key", "APP_KEY")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
Replace APP_ID and APP_KEY with your actual credentials.
3. Verify the response
A successful request returns JSON with the recognized content:
Example response
{
"text": "\\( x=\\frac{-b \\pm \\sqrt{b^{2}-4 a c}}{2 a} \\)",
"confidence": 0.9985,
"confidence_rate": 0.9985
}
If you see an error field instead, check that your app_id and app_key are correct and that your account is active.
Next steps
- Authentication reference — full details on API keys, app tokens, and per-endpoint auth requirements
- Process a PDF — submit documents for async OCR
- Process an image — single image processing with options