Redeem a pairing token: post the OAuth credential bundle back to the platform
Canonical pairing-redeem route used by @appstrate/connect-helper. Bearer-only — authenticated by the pairing token previously minted via POST /api/model-providers-oauth/pairing (carry as Authorization: Bearer appp_<token>). The pairing's userId / orgId / provider / owner and optional reconnect target are pinned at mint time, so a tampered helper cannot redirect the redeem to a different org, provider, owner or credential. The request carries no principal, so the member who minted the pairing is judged again on what the organization grants them at this moment, by the rules of the mint: a new connection needs model-provider-credentials:write (organization) or model-provider-credentials:connect (personal) and answers 403 without it, or once the member left; a reconnect needs the credential to still list reconnect for them and answers 404 otherwise. A personal credential answers 403 personal_model_credentials_disabled when the organization turned personal_model_credentials off after the mint. The token is single-use and consumed before anything is judged, the request body included: a refused redeem spends it (a retry answers 410) and is recorded on the pairing, which GET /pairing/{id} then reads as failed; a new pairing must be minted. Cookie/API-key requests 401. Server-side this re-derives identity slots defensively via the provider's extractTokenIdentity hook before creating or updating model_provider_credentials.
/api/model-providers-oauth/pair/redeemCookie session from Better Auth. Requires X-Org-Id header for org-scoped routes.
In: cookie
Request Body
application/json
curl -X POST "https://your-instance/api/model-providers-oauth/pair/redeem" \ -H "Content-Type: application/json" \ -d '{ "providerId": "string", "access_token": "string", "refresh_token": "string" }'{
"credentialId": "f568fec0-10b6-4b94-9daf-e62c50c9bf3e",
"providerId": "string",
"email": "[email protected]",
"available_model_ids": [
"string"
]
}{
"type": "https://docs.appstrate.dev/errors/validation-failed",
"title": "Validation Failed",
"status": 400,
"detail": "name: Invalid input: expected string, received undefined (+2 more)",
"code": "validation_failed",
"request_id": "req_abc123",
"errors": [
{
"field": "name",
"code": "required",
"message": "Invalid input: expected string, received undefined"
},
{
"field": "email",
"code": "invalid_format",
"message": "Invalid email address"
},
{
"field": "age",
"code": "invalid_type",
"message": "Invalid input: expected number, received string"
}
]
}{
"type": "https://docs.appstrate.dev/errors/unauthorized",
"title": "Unauthorized",
"status": 401,
"detail": "Invalid or missing session",
"code": "unauthorized",
"request_id": "req_abc123"
}{
"type": "https://docs.appstrate.dev/errors/forbidden",
"title": "Forbidden",
"status": 403,
"detail": "Insufficient permissions",
"code": "forbidden",
"request_id": "req_abc123"
}{
"type": "https://docs.appstrate.dev/errors/not-found",
"title": "Not Found",
"status": 404,
"detail": "Resource not found",
"code": "not_found",
"request_id": "req_abc123"
}{
"type": "http://example.com",
"title": "string",
"status": 0,
"detail": "string",
"instance": "string",
"code": "string",
"request_id": "string",
"param": "string",
"retry_after": 0,
"errors": [
{
"field": "string",
"code": "string",
"message": "string",
"title": "string",
"line": 1,
"column": 1,
"candidate_connections": [
{
"id": "string",
"label": "string",
"account_id": "string",
"owned_by_actor": true,
"needs_reconnection": true,
"scopes_granted": [
"string"
],
"missing_scopes": [
"string"
]
}
],
"connection_id": "string",
"missing_scopes": [
"string"
],
"remedy": "new_connection",
"owned_by_actor": true,
"required_scopes": [
"string"
],
"auth_key": "string",
"required_auth_key": "string",
"available_auth_keys": [
"string"
],
"source": "admin_pin",
"connect_url": "http://example.com",
"expiresAt": "2019-08-24T14:15:22Z",
"packageId": "string"
}
]
}