image-ocr

Exact captured content · path skills/image-ocr/SKILL.md · sha256 7e463b644dac86e8… · revision d251ed51e7922ccea9f85b2b02a5a2865379e445

Download the exact captured file

---
name: image-ocr
description: Read the text in images (screenshots, scans, photos of documents) with the AssetFeed OCR model. Use when the user gives an image file or image URL and wants its text. Up to 8 images per request.
---

# Image OCR

Sends images to the AssetFeed OCR model (`assetfeed/assetfeed-ocr-v1`) and returns the text in them. Model page: https://assetfeed.com/models/ocr. API docs: https://assetfeed.com/models/ocr/api.

## Requirements

- `ASSETFEED_API_KEY` set in the environment. Create a key at https://assetfeed.com/api-keys. Pricing: https://assetfeed.com/pricing.
- `curl`, `jq` and `base64`.
- The images are sent to `api.assetfeed.com`. Tell the user before sending a local file. Images sent to OCR with free-plan credits may be stored for up to 24 months and used to train AssetFeed models ([inference data policy](https://assetfeed.com/inference-data-policy), section 3).
- Up to 8 images per request, 15 MB each. Formats: png, jpeg, webp, gif. Image URLs must be http(s).

## Steps

1. For an image URL, send it as is:

```bash
jq -n --arg url "$IMAGE_URL" '{
  model: "assetfeed/assetfeed-ocr-v1",
  messages: [{role: "user", content: [{type: "image_url", image_url: {url: $url}}]}]
}' | curl -sS -X POST https://api.assetfeed.com/api/v1/models/chat/completions \
  -H "Authorization: Bearer $ASSETFEED_API_KEY" \
  -H "Content-Type: application/json" \
  -d @-
```

2. For a local file, encode it as a base64 data URL first. Set `MIME` to `image/png`, `image/jpeg`, `image/webp` or `image/gif`:

```bash
{ printf 'data:%s;base64,' "$MIME"; base64 < "$IMAGE_FILE" | tr -d '\n'; } > "$TMPDIR/ocr-image.txt"
jq -n --rawfile url "$TMPDIR/ocr-image.txt" '{
  model: "assetfeed/assetfeed-ocr-v1",
  messages: [{role: "user", content: [{type: "image_url", image_url: {url: $url}}]}]
}' | curl -sS -X POST https://api.assetfeed.com/api/v1/models/chat/completions \
  -H "Authorization: Bearer $ASSETFEED_API_KEY" \
  -H "Content-Type: application/json" \
  -d @-
rm "$TMPDIR/ocr-image.txt"
```

3. For several images, add one `image_url` part per image to `content`.
4. The text is in `choices[0].message.content` of the response. The request is not streamed. Return the text as read. Do not correct or rewrite it unless the user asks.

## Errors

- 401: the API key was rejected.
- 402: not enough credits. See https://assetfeed.com/pricing.
- 429: rate limit exceeded. Wait and retry.