Appearance
Customer sign-in recipes
Frege signs each customer in to your API with their own account, the way they already sign in: a one-time code, a password form, your OAuth server. From then on every tool call runs as them. One shared key for every caller is not offered: every customer would act as the same account.
You describe the sign-in as a recipe: steps that ask the customer something or call one of your sign-in operations, and outputs that say where the credential is. Each environment has its own recipe. The same sign-in serves every channel: MCP clients, the chat widget, Telegram and voice.
A complete recipe
This is the recipe of Frege's own demo shop, which signs in with a code sent by SMS. The spec marks startOtp, verifyOtp and refreshToken with x-frege-auth-op: true.
json
{
"security_scheme": "bearerAuth",
"steps": [
{"id": "phone", "type": "prompt", "prompt": {
"title": "Sign in to Legacy Demo Shop",
"description": "We send a six-digit code to your phone.",
"fields": [{"name": "phone", "label": "Phone number", "type": "tel", "required": true, "placeholder": "+998900000001"}],
"submit_label": "Send the code"}},
{"id": "start", "type": "call", "operation_id": "startOtp",
"body": {"phone": {"from": "prompt", "key": "phone"}}},
{"id": "code", "type": "prompt", "prompt": {
"title": "Enter the code",
"description": "The six digits sent by SMS.",
"fields": [{"name": "code", "label": "Code", "type": "text", "required": true, "placeholder": "000000"}],
"submit_label": "Sign in"}},
{"id": "verify", "type": "call", "operation_id": "verifyOtp", "body": {
"request_id": {"from": "response", "step": "start", "json_path": "request_id"},
"code": {"from": "prompt", "key": "code"}}}
],
"outputs": {
"access_token": {"step": "verify", "json_path": "token"},
"refresh_token": {"step": "verify", "json_path": "refresh_token"},
"subject": {"step": "verify", "json_path": "user.id"},
"phone": {"from": "prompt", "key": "phone"}
},
"expiry": {"mode": "at", "at": {"step": "verify", "json_path": "expires_at"}},
"refresh": {
"steps": [{"id": "renew", "type": "call", "operation_id": "refreshToken",
"body": {"refresh_token": {"from": "bundle", "key": "refresh_token"}}}],
"outputs": {
"access_token": {"step": "renew", "json_path": "token"},
"refresh_token": {"step": "renew", "json_path": "refresh_token"}},
"expiry": {"mode": "at", "at": {"step": "renew", "json_path": "expires_at"}}
}
}Save it, then test it:
bash
curl -X PUT "https://api.frege.io/v1/projects/$PROJECT/upstream/recipe" \
-H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: staging" \
-H "Content-Type: application/json" -d "{\"recipe\": $(cat recipe.json)}"The recipe
| Field | What it is |
|---|---|
security_scheme | The name of the spec's security scheme the credential fills. Optional when the spec has exactly one global scheme. |
steps | The sign-in, in order. |
outputs | Where the credential and the customer's identity come from. |
expiry | When the credential stops working. |
refresh | How to renew it without asking the customer again: its own steps, outputs and expiry. |
capture | Named values to keep from the sign-in for refresh and inject. Names match ^[a-z][a-z0-9_]{0,39}$. |
inject | Extra values Frege adds to tool calls, beside the credential. |
The security schemes Frege can fill: apiKey (with in and name), http with scheme bearer or basic, and oauth2 and openIdConnect, which are sent as a bearer token.
Steps
Every step has an id, unique in the recipe, and a type.
prompt: ask the customer
json
{"id": "phone", "type": "prompt", "prompt": {
"title": "Sign in", "description": "We send a code to your phone.", "submit_label": "Send the code",
"fields": [{"name": "phone", "label": "Phone number", "type": "tel", "required": true, "placeholder": "+998..."}]}}- At least one field. Field names match
^[a-z][a-z0-9_-]{0,39}$, are unique across the recipe, and may not beexternal_auth_id,carryorlang. title,description,label,placeholderandhelp_texttake a string, or a string per language:{"default": "Phone number", "ru": "...", "uz": "..."}.- Not allowed in
refresh: a renewal cannot ask anyone. - Each prompt can have its own page in your brand: HTML and CSS, no JavaScript (
PUT /v1/projects/{id}/upstream/connect-pages/{kind}).
call: call a sign-in operation
json
{"id": "verify", "type": "call", "operation_id": "verifyOtp",
"body": {"code": {"from": "prompt", "key": "code"}},
"headers": {"X-Client": {"from": "literal", "value": "frege"}}}operation_idmust name an operation markedx-frege-auth-op: true.path_params,query,headersandbodymap names to values. Every{path}parameter must be bound, and every required query or header parameter except the security scheme's own.- Body fields the spec types as integer, number or boolean are sent as those types.
- The URL is the spec's server plus the path, over
https. - A step that sends a secret goes only to the environment's own API host.
redirect: your OAuth server
For an API that signs in with OAuth 2 (authorization code), the customer is sent to your authorization page and back.
json
{"id": "oauth", "type": "redirect", "redirect": {
"authorization_endpoint": "https://auth.example.com/authorize",
"token_endpoint": "https://auth.example.com/token",
"client_id": {"from": "config", "key": "OAUTH_CLIENT_ID"},
"client_secret": {"from": "secret", "key": "OAUTH_CLIENT_SECRET"},
"scopes": ["orders.read", "orders.write"],
"pkce": true,
"token_auth": "client_secret_basic"}}- All endpoints are
https.userinfo_endpointis optional. client_secret, if any, must comefrom: "secret".client_idandparamstravel through the customer's browser, so they cannot read a secret.- PKCE is on by default, and must stay on for a public client (
token_auth: "none"). paramsmay not setresponse_type,client_id,redirect_uri,state,scope,code_challengeorcode_challenge_method.- At most one
redirectper sign-in. Inrefresh, atoken_refreshstep with"of": "<redirect step id>"renews its token.
Values
A value says where a step's input comes from: {"from": "<kind>", ...}. A prefix is put before it; it must end with its own space when one is wanted, as in "Bearer ".
from | Fields | Where |
|---|---|---|
literal | value | anywhere |
prompt | key: a prompt field | sign-in steps |
response | step, json_path | sign-in and refresh steps; the step must have called something |
config | key: a plain variable | anywhere |
secret | key: a secret variable | anywhere |
capture | key: a name in capture | refresh and inject |
bundle | key: access_token, refresh_token, session_token or api_key | refresh and inject |
now | format: unix (default), unix_ms or rfc3339 | anywhere |
digest | algorithm (md5, sha1, sha256, sha512), parts, separator, encoding | anywhere |
hmac | the fields of digest, and key | anywhere; hashes do not nest |
A json_path is dot-separated, with numbers for list positions: data.items.0.id. A leading $. is accepted. encoding is hex (the default), hex_upper, base64, base64url or base64_raw.
Variables and secrets are per environment:
bash
curl -X POST "https://api.frege.io/v1/projects/$PROJECT/variables" \
-H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: staging" \
-H "Content-Type: application/json" \
-d '{"name": "OAUTH_CLIENT_SECRET", "value": "...", "secret": true}'A name is unique in its environment, and whether it is secret is fixed when it is made. Secrets are stored encrypted and masked in test traces.
Outputs
outputs maps keys to where their value is found:
json
{"from": "response", "step": "verify", "json_path": "token"}
{"from": "response_header", "step": "verify", "header": "X-Session"}
{"from": "response_cookie", "step": "verify", "cookie": "sid"}
{"from": "prompt", "key": "phone"}
{"from": "secret", "key": "PARTNER_KEY"}from may be left out for response. For a cookie, use response_cookie: response_header refuses Set-Cookie.
| Keys | What they are |
|---|---|
access_token, session_token, api_key | The credential. One of them is required. |
refresh_token | Kept for refresh. |
subject, email, display_name, phone, username | Who the customer is. Main recipe only. |
A recipe whose outputs all come from: "secret" is refused: every customer would sign in as the same account.
Expiry
json
{"mode": "ttl", "ttl_seconds": 3600}
{"mode": "at", "at": {"step": "verify", "json_path": "expires_at"}, "assume_zone": "Asia/Tashkent"}An at value may be RFC 3339; a Unix time in seconds, or in milliseconds when it is above 10^11; or a local date and time (2026-11-30T15:04:05 or 2026-11-30 15:04:05), read in assume_zone, which such a value needs.
When the credential expires, Frege runs refresh. When it cannot renew, the customer is asked to sign in again, and the credential_expired hooks run.
Injection
inject adds values to every tool call, beside the credential:
json
"inject": [
{"in": "header", "name": "X-Tenant", "value": {"from": "capture", "key": "tenant"}},
{"in": "body", "name": "customer_id", "value": {"from": "capture", "key": "customer"}, "operations": ["createOrder"]}
]inisheader,query,cookie,pathorbody.operationslimits abodyinjection to some operations.- A name is injected once per place. A header or cookie cannot be the credential's own.
- A
pathvalue cannot be a secret, and the parameter must exist in the spec. - A call whose injected value is missing fails, unless the injection says
optional: true.
Testing
POST /v1/projects/{id}/upstream/recipe/test runs the sign-in against your real API and returns a trace of every request and answer. Send recipe to test a draft, or nothing to test the saved one.
bash
curl -X POST "https://api.frege.io/v1/projects/$PROJECT/upstream/recipe/test" \
-H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: staging" \
-H "Content-Type: application/json" -d '{}'status | What to do |
|---|---|
prompt | A step asks something. Send the answers as input, with the carry this answer returned: {"input": {"phone": "+998900000001"}, "carry": ...}. |
connected | Signed in. captured lists the credential parts kept, subject and identities who it is. |
failed | error says why; the trace shows each step's URL, headers, body, status and answer. |
"refresh": truealso runsrefreshafter the sign-in connects, and reports it apart asrefresh_status.- A test that connects is a real sign-in of a test customer, "Probe client", whose id is
default_client_id: the environment's sign-in hooks run for real. - Ten tests a minute per environment.
The customers
Every sign-in makes a customer of the environment, listed by GET /v1/projects/{id}/clients. Use a customer's id as client_id when you run a tool or an agent as them. A customer can be revoked (DELETE /v1/projects/{id}/clients/{clientID}), limited to some tools (PUT .../grants), archived, or purged with all their data.