Skip to content

API for AI agents

This page is for an AI agent, and for the person who sets one up. It covers the base URL, the key, the errors, and one worked example: a monitor started from a recipe and taken to active.

https://api.fravni.com

Every path starts /v1. The OpenAPI file lists every route a key reaches, with every request and response schema. Read it for anything this page leaves out.

Use a Fravni API key. Create one on the API keys page, in the app’s sidebar. It is shown once, so store it as a secret. Send it on every request:

Authorization: Bearer <key>

A key acts as the member who created it. It reaches only the routes in the OpenAPI file; any other route answers 401 session_required.

Every refusal has the same shape:

{
"error": {
"code": "machine_readable_code",
"message": "A sentence for a person.",
"details": null
}
}

Branch on code, never on message. details is null unless the code fills it. Codes are open, so new ones may appear: treat an unknown code by its HTTP status class.

The codes the worked example can hit:

  • 401 session_required: the route takes no key. Use a route from the OpenAPI file.
  • 401 invalid_api_key: the key is not live. Replace it.
  • 404 account_not_found: the key’s account is gone. Stop and tell a person.
  • 404 connection_not_found: no such connection in this account. Check the ID.
  • 404 recipe_not_found: no such recipe. List them with GET /v1/recipes.
  • 404 source_not_found: no such webhook in this account. Check the ID.
  • 404 monitor_not_found: no such monitor in this account. Check the ID.
  • 409 connection_over_limit: the account holds all the connections it may. Reuse one, or ask a person to delete one.
  • 409 connection_proof_not_applicable: the host is approved and needs no proof. Skip the proof.
  • 409 monitor_cap_reached: the account holds all the monitors it may. Ask a person.
  • 409 invalid_state: the monitor is not a draft, so its webhook is fixed. details.state names its state.
  • 409 source_cap_reached: the account holds all the webhooks it may. Ask a person to delete an unused one.
  • 409 connection_unbound: the working copy has no connection. Save one with a connection_id.
  • 409 connection_deleted: the working copy’s connection was deleted. Bind another and save it.
  • 409 draft_changed: the monitor changed since you read it. Read it again, then retry with its ETag as If-Match.
  • 413 content_too_large: the request body is too large. Send a smaller event.
  • 422 validation_error: the request breaks its schema. Fix it against the OpenAPI file.
  • 422 invalid_id: an ID in the path is malformed. Send the ID as the API returned it.
  • 422 working_copy_invalid: the working copy’s definition is incomplete or wrong. Fix it and save it.
  • 422 activation_failed: the publish failed a check. details.checks names each one; fix them, then publish again.
  • 429 rate_limited: too many requests. Wait the Retry-After seconds, then retry.
  • 503 fetcher_unavailable: Fravni could not complete the read; nothing was recorded. Retry later.
  • 503 rate_limiter_unavailable: a passing outage. Wait the Retry-After seconds; a quick retry will not help.
  • 503 service_unavailable: a passing fault. Retry shortly.

Every other code is in the OpenAPI file, per operation.

The monitor checks that your app grants the right entitlement when Stripe reports a paid invoice. Each step shows one request and the fields that matter. The OpenAPI file has the full schemas.

1. Connect your API and prove you control it

Section titled “1. Connect your API and prove you control it”

POST /v1/connections

{
"name": "Billing API",
"host": "api.example.com",
"credential": "<your API's token>"
}

Keep the response’s id. Fravni reads your API through this connection, but only once the account proves it controls the host. The response’s proof object holds the token and both ways to place it: serve it as a file at file_url, or put it in a DNS TXT record named txt_name. A person may have to place it. A connection to an approved host reads verified already and needs no proof.

POST /v1/connections/{id}/proof

{ "method": "file" }

Send "dns" for the DNS record. A result of passed proves the connection. On failed, the reason says why: fix it and retry.

POST /v1/recipes/stripe.invoice_paid.entitlement/start?name=Billing%20entitlement

The answer is a draft monitor with no webhook yet. Keep its id, its definition and its ETag header. Its warnings name the holes to fill, each by path:

{ "path": ["destination", "path"], "reason": "required" }

PUT /v1/monitors/{id}/source, with the header If-Match: <the last ETag>

{ "source_type": "stripe" }

This makes a new webhook for the monitor. Keep the answer’s source.source_id and its new ETag. To share a webhook another monitor uses, send its source_id too.

PUT /v1/monitors/{id}/definition, with the header If-Match: <the last ETag>

Send the started definition back, its holes filled and connection_id added. These are the members that change:

{
"destination": {
"path": "/v1/customers/{customer_id}",
"expectations": [
{ "field_path": "id", "expected": { "field": "customer_id" }, "identity": true },
{ "field_path": "plan.entitlement", "expected": { "field": "entitlement" }, "identity": false },
{ "field_path": "active", "expected": true, "identity": false }
]
},
"translated_fields": [
{
"translate_from": "price_id",
"name": "entitlement",
"data_type": "string",
"pairs": [{ "input": "<your Stripe price ID>", "output": "pro" }]
}
],
"connection_id": "<the connection's id>"
}

In the app, a pair’s input and output show as From and To.

Each save overwrites the monitor’s working copy and answers a new ETag. Keep it: the publish in step 8 sends it as If-Match.

PUT /v1/sources/{source_id}/secret

{ "secret": "whsec_..." }

It is the signing secret of the Stripe webhook endpoint that sends this webhook its events. A person may have to copy it from Stripe.

Steps 6 and 7 are optional.

POST /v1/tester/sample-runs

{
"monitor_id": "<the monitor's id>",
"sample": { "type": "invoice.paid", "data": { "object": { "...": "..." } } }
}

Send a real invoice.paid event as sample. This runs the working copy you saved and reads nothing. An outcome of resolved shows the fields Fravni takes from the event and the request it would send.

POST /v1/tester/test-reads, with the same body. Fravni makes one real read of your API for the sample and judges the record. read.outcome is match when the record holds what the event says it should. The publish reads nothing, so this step is the only way to see your API’s answer before the monitor starts.

If you ran steps 6 and 7, show their results to a person. A correct record, a wrong or missing record and an unreadable API each look different, and the person decides whether the monitor is right. Either way, publish only on a person’s go-ahead:

POST /v1/monitors/{id}/publish, with the header If-Match: <the ETag from step 4>

It takes no body. The publish freezes the working copy and starts the monitor: it answers with state active. A refusal is 422 activation_failed, its details.checks naming each failing check.