Operity

Quickstart: from nothing to an agent's first metered call

About five minutes. You need Python 3.10 or newer and an email address.

Everything here uses test credits. Nothing is real money, and each inbox can fund agents with up to 20 test credits a month. That allowance belongs to the inbox, not the account: you+work@gmail.com and y.o.u@gmail.com are separate accounts that share you@gmail.com's twenty. It renews on the first of each month (UTC). More is granted by hand: write to support@operity.co.

This page is executed, block by block, on a clean machine by Operity's own acceptance tests, against the live instance. If it stops working, the tests fail.

1. Get an API key

  1. Open https://operity.vercel.app/app, enter your email address and press Send me a link.
  2. Open the link in the email in the same browser, on the same device: it is tied to the browser that asked for it and will not work anywhere else. If you read email on your phone, ask for the link from your phone's browser. It works once, expires in 15 minutes, and creates your account if you did not have one.
  3. Press API keys, name a key, press Create key, and copy it. It is shown once and never again.

Put the key in your shell's environment. Nothing below prints it or writes it to disk:

export OPERITY_API_KEY='opk_...the key you copied...'

OPERITY_BASE_URL is optional and defaults to https://operity.vercel.app.

2. Install the client

The client library is served by the instance itself. It depends on cryptography and httpx, nothing else.

python3 -m pip install --quiet --disable-pip-version-check "${OPERITY_BASE_URL:-https://operity.vercel.app}/sdk/operity_client-0.1.0-py3-none-any.whl"

3. Register an agent, fund it, make a metered call

Save this as quickstart.py and run it with python3 quickstart.py:

import os
import uuid

import operity_client

base_url = os.environ.get("OPERITY_BASE_URL", "https://operity.vercel.app")
principal = operity_client.Principal(os.environ["OPERITY_API_KEY"], base_url=base_url)

# The agent's own keypair. The private half never leaves this machine: the
# agent signs every request with it, and the key you created above cannot act
# as the agent. Keep keypair.seed_bytes() somewhere safe if you want the agent
# back tomorrow.
keypair = operity_client.Keypair.generate()
record = principal.create_agent(f"quickstart-{uuid.uuid4().hex[:8]}", keypair)

# Fund it with one test credit. The reference names the payment the credits
# stand for; each reference is redeemable once.
principal.fund(record.id, 1_000_000, reference=f"quickstart-{uuid.uuid4().hex}")

# Now act AS the agent: a signed request, metered against its balance.
agent = operity_client.Agent(record.id, keypair, base_url=base_url)
before = agent.me().balance_uc
result = agent.action("retrieval")
after = agent.me().balance_uc

assert before - after == result.cost_uc > 0
print(f"first metered call: ok — cost {result.cost_uc} µc, balance {after} µc")

Amounts are integer micro-credits: 1 credit is 1,000,000 µc.

4. What next

Read the stated limitations before relying on a verification result, and the wire format if you are writing a client in another language.