Skip to content

First call

Send an image, read its text with ppocr-v6 and see what the call cost. The smoke run needs no API key and no sign-up: it runs on the free tier.

Models: ppocr-v6 · Without a key: Everything · Languages: Python, TypeScript, Go, curl · Try in Playground (opens in a new tab) · Source on GitHub (opens in a new tab)

A first integration has to get four things right before anything else: authentication, sending an image, reading the result and understanding the bill. This example does each once, with nothing else in the way.

  1. GET /v1/models: free, lists the models and their prices.
  2. With a key only, POST /v1/images: upload the file once and get a handle (img_...). Free. On the free tier there is no upload: the image goes inline as base64 (up to 4 MiB decoded).
  3. POST /v1/ocr with the image or the handle: the recognised lines, plus billing and timing.

Setup and run in each language

Commands for the smoke set, run from the repository root. The smoke set needs no API key: it runs on the free tier. The full set needs a key; the cap makes the client refuse calls that could exceed it.

Requires: Python 3.12, uv 0.5

cd use-cases/00-quickstart/python
uv sync --frozen
uv run --frozen python main.py --manifest ../assets/smoke/manifest.json --out out
cd use-cases/00-quickstart/python && uv run main.py
# or: bash use-cases/00-quickstart/curl/run.sh
# or: cd use-cases/00-quickstart/typescript && pnpm install && node main.ts
# or: cd use-cases/00-quickstart/go && go run .

No key is needed: the call is served by the free tier under the Cookbook’s shared project (see how the recipes authenticate (opens in a new tab)). To run with a key instead, set FOLDBUN_API_KEY; the call is then charged at the list price and the image is uploaded once and sent by handle. Set FOLDBUN_PROJECT_ID to use your own project and its limits.

Each implementation writes out/result.json in the format of contract/result.schema.json.

The client is created once. The key is optional and comes from FOLDBUN_API_KEY; the project ID comes from FOLDBUN_PROJECT_ID and defaults to the Cookbook’s. Neither is ever printed.

Source: python/main.py (opens in a new tab)

# No FOLDBUN_API_KEY: the free tier, with the Cookbook's shared project (FOLDBUN_PROJECT_ID to use your own).
client = sc.StackClient(max_concurrency=args.concurrency) # FOLDBUN_API_KEY, FOLDBUN_PROJECT_ID, FOLDBUN_API_BASE
try:
who = client.whoami() # shows who is calling: a project (free tier) or an account (API key)
except sc.StackError as err:
print(f"{err.status} {err.code}: {err.message}", file=sys.stderr)
return EXIT_NO_KEY if err.code == "missing_api_key" else EXIT_FAILED
print(f"free tier, project {who['project']['id']}" if client.free else f"key accepted; balance {who['balance']} credits")

An image can be sent inline as base64, which is simplest for one call and the only way on the free tier, or uploaded once (with a key) and referenced by its handle, which suits several calls or models on the same image and is required in batches. url inputs are not available yet.

Source: python/main.py (opens in a new tab)

if client.free or item.get("imageInput") == "base64":
image = sc.image_base64(data) # inline: simplest for a single call, and the only form the free tier takes
else:
uploaded = client.upload(data, content_type) # needs a key; the handle can be reused for 7 days at most
image = sc.image_handle(uploaded["id"])

The call itself, and how to read what it cost:

Source: python/main.py (opens in a new tab)

result = client.post("/v1/ocr", {"model": "ppocr-v6", "image": image}, tag=item["id"])
for line in result["lines"]:
print(f" {line['confidence']:.2f} {line['text']}")
price = result["billing"]["total"] # list price in credits
print(f" list price {price} credits (free tier, not charged)" if client.free else f" list price {price} credits, charged {result['cost']}")

One ppocr-v6 call has a list price of 0.25 credits. A smoke run is free on the free tier: the run prints that value labelled “free tier, not charged”, and nothing is debited. With a key, every call is charged at the list price.

Run Calls List price (credits) Charged (credits)
smoke 1 0.25 0

assets/smoke/settings.webp is a synthetic screenshot made for Foldbun Stack and released under CC0 1.0; see assets/smoke/ATTRIBUTION.csv. Rights holders can request removal of an image or dataset through the contact page (opens in a new tab).