Appearance
Your OpenAPI spec
Frege reads your OpenAPI document and makes one tool per operation. This page is what it reads, the x-frege-* extensions that tell it what it cannot guess, and the settings that decide what the tools may do.
Uploading
Each environment holds one spec. Upload the document itself as the body, JSON or YAML, up to 5 MB:
bash
curl -X POST "https://api.frege.io/v1/projects/$PROJECT/spec" \
-H "Authorization: Bearer $TOKEN" \
-H "X-Frege-Stage: staging" \
--data-binary @openapi.yaml- The upload is live in its environment as soon as it is stored. There is no draft. That is why the request must name the environment with
X-Frege-Stage. - An environment that already holds a spec answers
409: delete it first withDELETE /v1/projects/{id}/spec. - The document must declare
openapi: 3.x. OpenAPI 3.1 is converted to 3.0 for Frege's use, and itswebhooksare kept apart from the tools. A Swagger 2 document is refused: convert it to OpenAPI 3 first. servers[0].urlmust be an absolutehttporhttpsaddress. Every call goes there.POST /v1/projects/{id}/spec/validatechecks a document without storing it.GET /v1/projects/{id}/spec/lintgrades each tool of the spec the environment serves: no description, nooperationId, a duplicate name, a body without a schema, an extension Frege ignores, noservers.POST /v1/projects/{id}/spec/promotecopies Staging's spec, and its sign-in recipe, to Production.
From operations to tools
Each operation becomes one tool:
- Name. The
operationId. An operation without one is named from its method and path:GET /users/{id}/ordersbecomesget_users_id_orders. Repeated names get_2,_3in spec order, and the lint warns about them. - Description and input. From the operation's summary and description, and its parameters and request body. A model chooses tools by what they say, so good summaries make better tools.
- Credential. Each call carries the signed-in customer's credential, the way the spec's security scheme says:
apiKey(in a header, query or cookie),httpbearerorbasic, oroauth2andopenIdConnect(sent as a bearer token). See Customer sign-in recipes. - Left out. Operations marked
x-frege-auth-op(Frege performs them itself) and OpenAPI 3.1 webhooks.
GET /v1/projects/{id}/operations lists the tools with their tool_name and JSON Schema input_schema.
Reads and writes
An operation is a write unless its method is GET, HEAD or OPTIONS. The decision is the method's, never the operation's name. Mark a read as a write with x-frege-mutating: true. Nothing marks a POST as a read.
Retries
When your API answers 503, or the connection fails on the way, Frege sends the call again, up to three attempts in all, honouring Retry-After up to 30 seconds. GET, HEAD, OPTIONS, PUT and DELETE are retried; POST and PATCH only when marked x-frege-idempotent: true. A 429 is not retried: the model is told to wait.
Extensions
Put them on an operation object, next to operationId. A flag is on when it is true, or the text "true", "1" or "yes"; write true.
| Extension | Value | What Frege does |
|---|---|---|
x-frege-auth-op | true | The operation signs in (log in, verify a code, refresh a token). It is not offered as a tool; your sign-in recipe calls it. A recipe may call only operations with this mark. |
x-frege-mutating | true | The operation is a write whatever its method: the write policy applies, and its answer is never shared. |
x-frege-idempotent | true | A POST or PATCH that is safe to send twice, so a 503 or a network failure is retried. |
x-frege-max-body-bytes | a positive number | The largest request body the operation accepts. Photos sent by reference are shrunk to fit. The default is 28 MB. |
x-frege-shared-cache | {"ttl": 60} | The answer is the same for every customer: one call to your API answers all of an environment's customers for ttl seconds (1 to 3600). Reads only. |
x-frege-value | an object | The call moves money or another counted value; the wallet caps it. See below. |
x-frege-webhook | the webhook's name | Frege writes this on OpenAPI 3.1 webhooks it converts. An operation that carries it is not a tool. |
Frege writes two more itself when it reads a spec: x-frege-generated-id on an operation it named, and x-frege-content-media-type to keep a 3.1 contentMediaType through the conversion. You do not need to write them.
yaml
paths:
/session:
post:
operationId: verifyOtp
x-frege-auth-op: true
/orders/{id}/cancel:
post:
operationId: cancelOrder
summary: Cancel an order that has not shipped
x-frege-idempotent: true
/market/status:
get:
operationId: marketStatus
x-frege-shared-cache: { ttl: 60 }Sign-in operations without editing the spec
PUT /v1/projects/{id}/spec/auth-ops with {"operation_ids": ["startOtp", "verifyOtp"]} marks exactly those operations as sign-in operations and removes the mark from every other one. Frege rewrites the stored document to match.
Per-environment overrides
PUT /v1/projects/{id}/operations/{operationID}/settings sets idempotent and max_body_bytes for one operation in one environment, over what the spec says. GET /v1/projects/{id}/operations/settings shows each value and where it came from (environment, spec or default).
Shared answers: use with care
x-frege-shared-cache is for answers that do not depend on who asks: whether the market is open, a price list, the FAQ. If an answer carries anything of the customer's own, do not mark it: other customers would see it.
- Shared within one environment of one project only.
- Each customer must still be signed in; a cached answer is never a way around your sign-in.
- Only successful answers (
2xx, up to 1 MB) are kept. - On a write the mark is ignored, and the lint says so (
shared_cache_ignored).
The wallet: x-frege-value
When a tool moves money, say so, and set how much an agent may move for a customer. Frege holds no money and moves none: it computes the amount from the call's real arguments, never from what the model says, and caps and records the calls your API makes.
json
"x-frege-value": {
"amount": {"from": "product", "of": [{"from": "ref", "path": "args.quantity"}, {"from": "ref", "path": "args.price"}]},
"unit": {"from": "literal", "value": "UZS"},
"side": {"from": "ref", "path": "args.side"},
"settled": {"from": "ref", "path": "result.order.total"},
"reference": {"from": "ref", "path": "result.order.id"}
}amountandunitare required. Each part is a value of Frege's expression language over the call's arguments (args);settledandreferencemay also read your API's answer (result).productmultiplies its parts.unitmust come out as a three-letter capital code (UZS,USD), or the call is refused.- A value that does not compile makes the lint warn
value_invalid, and every call to the operation is refused.
Then set a mandate per currency, for the environment or for one customer:
bash
curl -X PUT "https://api.frege.io/v1/projects/$PROJECT/wallet/mandates/UZS" \
-H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: live" \
-H "Content-Type: application/json" \
-d '{"per_call": 50000000, "per_day": 200000000, "ask_above": 10000000, "sides": ["buy"], "time_zone": "Asia/Tashkent"}'| Field | What it does |
|---|---|
per_call, per_day, per_week | A call past one is refused. Amounts are in minor units (tiyin, cents). A day and a week begin in time_zone (UTC by default). per_call may not exceed per_day, nor per_day per_week. |
ask_above | A call above it waits for the customer's approval, even where writes are allowed. |
sides | Which sides may move at all; empty means any. |
scope | A condition the arguments must meet. |
customer_id | Set the mandate for one customer instead of the environment. |
A call whose amount cannot be computed always waits for approval. Where no one can be asked (MCP clients, the API), a call that would wait is refused. GET /v1/projects/{id}/wallet/moves is the ledger: what each valued call moved, for whom, and whether it went through (executed), was refused by your API (failed) or got no answer (unknown, still counted).
Write policy
Each environment decides what the AI may change. Organization admins set it:
bash
curl -X PUT "https://api.frege.io/v1/projects/$PROJECT/write-policy" \
-H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: live" \
-H "Content-Type: application/json" -d '{"policy": "ask"}'policy | What happens to a write |
|---|---|
allow | It runs. |
ask | It pauses and runs only when a person approves it: in the playground, the chat widget and Telegram. Where nobody can be asked (Claude and other MCP clients that cannot show a form, the API) it is refused. |
deny | It is refused before your API is called, and before the customer's credential is even read. |
A refused call answers 403 with code call_denied on the API, and an isError result on MCP.
Tool mode
An environment serves either its generated tools or its intent tools, never both:
bash
curl -X PUT "https://api.frege.io/v1/projects/$PROJECT/tool-mode" \
-H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: live" \
-H "Content-Type: application/json" -d '{"mode": "intent"}'generated(the default): one tool per operation.intent: only the environment's enabled intent tools that compile, plus the documentation tools. See Intent tools.
A switch that would take tools away from an agent answers 409, naming each agent and what it would lose. Send "force": true to switch anyway. Only organization admins switch.