> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abstract.inc/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect Abstract

> Let customers authorize your app and pay for inference from their Abstract account without sharing an API key.

Connect Abstract lets your customers approve your app, choose its models, and set a monthly
usage limit. Inference bills their Abstract account under its existing credit and Pass rules.
Your app receives renewable access tokens. It never receives the customer's API key.

## Register your app

Sign in to [Connected apps](https://platform.abstract.inc/connections), then choose **Register an app**.
Enter a name, an HTTPS homepage, and an HTTPS callback URL on the same origin. URLs cannot contain
credentials, query strings, or fragments. The callback must match exactly on authorization and
code exchange. Use a separate registration for each environment.

Save the client ID. Registrations are public OAuth clients using S256 PKCE; there is no client
secret. The app name is developer-supplied, and consent shows its domain. Registration is not
verification or endorsement by Abstract.

## Ask the customer to connect

For each attempt, generate a cryptographically random `state` and a PKCE `code_verifier` of
43–128 characters (`A–Z`, `a–z`, `0–9`, `-`, `.`, `_`, `~`). Save both against your customer's
browser session on your backend. Compute `code_challenge` as the unpadded base64url encoding of
SHA-256 of the verifier.

Send the browser to:

```text theme={"theme":"css-variables"}
https://platform.abstract.inc/connect/authorize
  ?response_type=code
  &client_id=YOUR_CLIENT_ID
  &redirect_uri=YOUR_URL_ENCODED_CALLBACK
  &scope=inference
  &state=YOUR_RANDOM_STATE
  &code_challenge=YOUR_S256_CHALLENGE
  &code_challenge_method=S256
```

The customer signs into Abstract, selects allowed models, enters a monthly limit in USD, and
approves. The browser returns to your callback with `code`, the original `state`, and
`iss=https://platform.abstract.inc`. Cancellation returns `error=access_denied` instead of a code.
Check both `state` and `iss` before proceeding. Never log the callback query.

## Exchange the code

From your backend, POST URL-encoded fields to `https://api.abstract.inc/v1/oauth/token`:

```text theme={"theme":"css-variables"}
grant_type=authorization_code
client_id=YOUR_CLIENT_ID
code=RETURNED_CODE
redirect_uri=YOUR_REGISTERED_CALLBACK
code_verifier=YOUR_SAVED_VERIFIER
```

The code expires after two minutes and can be exchanged once. A successful response is:

```json theme={"theme":"css-variables"}
{
	"access_token": "<secret>",
	"token_type": "Bearer",
	"expires_in": 900,
	"refresh_token": "<secret>",
	"refresh_token_expires_in": 2592000,
	"scope": "inference",
	"connection_id": "<connection id>",
	"session_id_prefix": "<connection id>:"
}
```

Store tokens as secrets on your backend, associated with the customer who began the flow.
Do not put them in URLs, logs, analytics, or browser storage. The token endpoint is intended
for backend calls and does not enable browser CORS.

Use the access token in the `Authorization: Bearer` header on inference requests. It authorizes:

* `POST /v1/chat/completions` and retrieval of this connection's completions.
* `POST /v1/get_action`, `POST /v1/end_session`, and `GET /v1/ready` for approved robot models.
* `POST /v1/sessions` for direct sessions on approved models.
* `GET /v1/models`, filtered to approved models in that catalog.

Tokens cannot manage keys, billing settings, compute nodes, datasets, fine-tuning, or private
deployments. Access to models added later requires the customer to approve again.

For robot calls, begin each `session_id` with the returned `session_id_prefix`, then append a
unique episode identifier. This isolates your app's episodes from other apps on the account.
`POST /v1/sessions` generates a session ID with this prefix when one is omitted. Pass that ID
on subsequent calls. This does not change the model's observation or action contract.

## Renew access

Access tokens expire after 15 minutes. Before expiry, POST these URL-encoded fields to the same
token endpoint:

```text theme={"theme":"css-variables"}
grant_type=refresh_token
client_id=YOUR_CLIENT_ID
refresh_token=YOUR_CURRENT_REFRESH_TOKEN
```

Save both replacement tokens atomically. Refresh invalidates the previous access and refresh
tokens. Only one refresh may run at a time per connection. Refresh tokens expire after 30 days
without renewal. Reusing an already consumed refresh token revokes the connection's current
credentials. If a refresh response is lost, reconnect; do not retry the old refresh token.

The OAuth metadata is at
`https://platform.abstract.inc/.well-known/oauth-authorization-server`.

## Limits and disconnection

Customers can inspect usage, change the monthly limit, or disconnect in **Connected apps**.
A limit includes settled usage and outstanding maximum-cost reservations, at model list rates,
including usage covered by a Pass. It resets at the beginning of each calendar month in UTC.
Reconnecting does not erase spending history. The account's own payment and spending checks
still apply. Nothing falls back to charging the app developer.

Disconnecting stops new requests and token renewals. Requests already authorized can finish.
A direct robot session's already reserved block remains usable until its ticket expires
(five minutes); obtaining another block requires a valid connected-app token and available budget.
Lowering a cap does not cancel work already reserved.

| Response | Meaning | Action |
| - | - | - |
| `401 invalid_api_key` | Access token expired, was replaced, or connection was revoked. | Renew once using your current refresh token; reconnect if refused. |
| `403 insufficient_scope` | The route or private deployment is outside inference access. | Use an authorized inference route. |
| `403 model_not_authorized` | Customer did not approve that model. | Ask the customer to reconnect and select it. |
| `429 app_spend_limit_exceeded` | The request's reservation would cross the app limit. | Reduce the request or have the customer adjust the limit. |
| `400 invalid_session_id` | A robot session lacks the connection's prefix or is malformed. | Use the returned prefix and a unique episode identifier. |
| OAuth `invalid_grant` | Code or refresh token is invalid, expired, consumed, or revoked. | Begin a new connection flow. |

The normal inference errors for insufficient account credit and account spending limits also apply.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.