Skip to content

OAuth token endpoint

POST
/oauth/token
curl --request POST \
--url https://api-dev.mindflow.io/v1/oauth/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=authorization_code \
--data code=f9SpG6WosBK5KY3RStV4QRWLZADu1XR4TuCS3BnNQAo \
--data code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk \
--data client_id=UJu3PB7RPORHyi0mXo8frl-NSQ58Tfh2mjjSj4xHlrY \
--data redirect_uri=myapp://oauth/callback

Exchanges an authorization code, or refreshes an access token. Send application/x-www-form-urlencoded. No bearer token.

For grant_type=authorization_code, send code, code_verifier, client_id, and redirect_uri. Do this within 60 seconds of configure. redirect_uri must match the authorize call.

For grant_type=refresh_token, send refresh_token and client_id. The response includes a new refresh token. Use that value next time. A token that was already replaced is rejected.

resource is optional on both grant types. When sent, it must be this tenant’s Platform API URL or MCP resource URL; any other value is 400 invalid_target. It must be the resource stored on the grant; a mismatch is 400 invalid_grant. Omit it to keep that stored audience. Every access token carries it as aud.

When client_id is a Client ID Metadata Document URL, the cached document is used and fetched again once it expires. 401 invalid_client when it can no longer be loaded or validated.

Form fields for one token call. Send the fields required by grant_type. Extra fields are ignored.

Media typeapplication/x-www-form-urlencoded

Form fields for one token call. Send the fields required by grant_type. Extra fields are ignored.

object
grant_type

Which grant to run. Use authorization_code to redeem a code. Use refresh_token to rotate an access token.

string
Allowed values: authorization_code refresh_token
code

Authorization code from the configure redirect. Required when grant_type is authorization_code. It expires 60 seconds after configure.

string
<= 2048 characters
code_verifier

PKCE verifier that produced code_challenge. 43 to 128 unreserved characters. Required for authorization_code.

string
>= 43 characters <= 128 characters /^[A-Za-z0-9\-._~]+$/
refresh_token

Refresh token from the previous token response. Required when grant_type is refresh_token.

string
<= 2048 characters
client_id

Client id from registration, or the HTTPS URL of the client’s Client ID Metadata Document. Required for both grant types.

string
<= 256 characters /^(?:[A-Za-z0-9_-]+|https://[^\s#]+)$/
redirect_uri

Same redirect URI sent to authorize. Required for authorization_code.

string format: uri
<= 2048 characters
resource

Optional RFC 8707 resource indicator. When sent, it must be this tenant’s Platform API URL (https://api-{tenant}.mindflow.io/v1) or MCP resource URL (https://mcp-{tenant}.mindflow.io/mcp), and the resource stored on the grant. Omit it to keep that audience.

string format: uri
<= 2048 characters
Examples

Redeem an authorization code

grant_type=authorization_code&code=f9SpG6WosBK5KY3RStV4QRWLZADu1XR4TuCS3BnNQAo&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk&client_id=UJu3PB7RPORHyi0mXo8frl-NSQ58Tfh2mjjSj4xHlrY&redirect_uri=myapp%3A%2F%2Foauth%2Fcallback

Issued OAuth tokens (access_token, token_type, expires_in, optional refresh_token).

Media typeapplication/json

New access token and a refresh token to store for the next refresh.

object
access_token
required

Opaque OAuth access token (Bearer) for Platform REST routes that accept user tokens and for GET /oauth/whoami. It is not the identity JWT.

string
<= 2048 characters
token_type
required

Always Bearer (OAuth token type). Send the access token as Authorization: Bearer <token>.

string
Allowed values: Bearer
expires_in
required

Seconds until access_token stops working. The value is 3600.

integer format: int32
>= 1 <= 3600
refresh_token
required

Opaque token for the next refresh. It replaces any previous refresh token for this approval. It lasts 14 days.

string
<= 2048 characters
Example
{
"access_token": "f9SpG6WosBK5KY3RStV4QRWLZADu1XR4TuCS3BnNQAo",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "UJu3PB7RPORHyi0mXo8frl-NSQ58Tfh2mjjSj4xHlrY"
}
X-RateLimit-Limit
integer format: int32
>= 1 <= 1000
Example
1000

Maximum number of requests allowed in the current window. Present when this response is rate limited.

X-RateLimit-Remaining
integer format: int32
<= 1000
Example
42

Number of requests still allowed in the current window. 0 means the next call can return 429 until the window resets.

X-RateLimit-Reset
string format: date-time
<= 29 characters
Example
2026-03-20T15:31:00.000Z

Time when the current window resets, as ISO 8601 UTC. After this time, X-RateLimit-Remaining starts over.

Retry-After
integer format: int32
>= 1 <= 3600
Example
30

HTTP Retry-After value in seconds. Wait at least this long before retrying a 429 response.

Access-Control-Allow-Origin
string
Allowed values: *
Example
*

CORS Access-Control-Allow-Origin value. Origin allowed to read this response from a browser. * means any origin may read it.

The request was invalid. Common causes include:

  • Invalid timestamp format.
  • Using cursor with before or after.
  • Missing limit when using before or after.
  • Invalid field names in the fields parameter.

See the error response for specific details about what went wrong.

Media typeapplication/json
object
type

URI reference identifying the problem type. When absent, “about:blank” per RFC 9457 Section 3.1.1.

string format: uri-reference
default: about:blank <= 2048 characters
title
required

Short, human-readable summary of the problem type (RFC 9457 Section 3.1.3).

string
<= 256 characters /^[^\p{C}]+$/
status
required

HTTP status code for this occurrence (advisory; same as response status) (RFC 9457 Section 3.1.2).

integer format: int32
>= 100 <= 599
detail

Human-readable explanation specific to this occurrence (RFC 9457 Section 3.1.4).

string
<= 500 characters
instance

URI reference identifying the specific occurrence (RFC 9457 Section 3.1.5).

string format: uri-reference
<= 2048 characters
code

Always BAD_REQUEST on this response. Read detail for which value to change, then send a corrected request.

string
Allowed values: BAD_REQUEST
Example
{
"type": "about:blank",
"title": "Bad Request",
"status": 400,
"detail": "The request body or query is invalid.",
"code": "BAD_REQUEST"
}
X-RateLimit-Limit
integer format: int32
>= 1 <= 1000
Example
1000

Maximum number of requests allowed in the current window. Present when this response is rate limited.

X-RateLimit-Remaining
integer format: int32
<= 1000
Example
42

Number of requests still allowed in the current window. 0 means the next call can return 429 until the window resets.

X-RateLimit-Reset
string format: date-time
<= 29 characters
Example
2026-03-20T15:31:00.000Z

Time when the current window resets, as ISO 8601 UTC. After this time, X-RateLimit-Remaining starts over.

Retry-After
integer format: int32
>= 1 <= 3600
Example
30

HTTP Retry-After value in seconds. Wait at least this long before retrying a 429 response.

Access-Control-Allow-Origin
string
Allowed values: *
Example
*

CORS Access-Control-Allow-Origin value. Origin allowed to read this response from a browser. * means any origin may read it.

Authentication failed. The request lacks valid credentials or the provided credentials are invalid.

Ensure you have:

  • A valid API key or token.
  • Proper authentication headers.
  • Required permissions.
Media typeapplication/json
object
type

URI reference identifying the problem type. When absent, “about:blank” per RFC 9457 Section 3.1.1.

string format: uri-reference
default: about:blank <= 2048 characters
title
required

Short, human-readable summary of the problem type (RFC 9457 Section 3.1.3).

string
<= 256 characters /^[^\p{C}]+$/
status
required

HTTP status code for this occurrence (advisory; same as response status) (RFC 9457 Section 3.1.2).

integer format: int32
>= 100 <= 599
detail

Human-readable explanation specific to this occurrence (RFC 9457 Section 3.1.4).

string
<= 500 characters
instance

URI reference identifying the specific occurrence (RFC 9457 Section 3.1.5).

string format: uri-reference
<= 2048 characters
code

Always MISSING_OR_INVALID_TOKEN on this response. Branch on this value, not on detail.

string
Allowed values: MISSING_OR_INVALID_TOKEN
Example
{
"type": "about:blank",
"title": "Unauthorized",
"status": 401,
"detail": "The bearer token is missing or invalid.",
"code": "MISSING_OR_INVALID_TOKEN"
}
X-RateLimit-Limit
integer format: int32
>= 1 <= 1000
Example
1000

Maximum number of requests allowed in the current window. Present when this response is rate limited.

X-RateLimit-Remaining
integer format: int32
<= 1000
Example
42

Number of requests still allowed in the current window. 0 means the next call can return 429 until the window resets.

X-RateLimit-Reset
string format: date-time
<= 29 characters
Example
2026-03-20T15:31:00.000Z

Time when the current window resets, as ISO 8601 UTC. After this time, X-RateLimit-Remaining starts over.

Retry-After
integer format: int32
>= 1 <= 3600
Example
30

HTTP Retry-After value in seconds. Wait at least this long before retrying a 429 response.

Access-Control-Allow-Origin
string
Allowed values: *
Example
*

CORS Access-Control-Allow-Origin value. Origin allowed to read this response from a browser. * means any origin may read it.

Too many requests. The request rate limit has been exceeded.

Please wait until the rate limit window resets before making additional requests.

Media typeapplication/json
object
type

URI reference identifying the problem type. When absent, “about:blank” per RFC 9457 Section 3.1.1.

string format: uri-reference
default: about:blank <= 2048 characters
title
required

Short, human-readable summary of the problem type (RFC 9457 Section 3.1.3).

string
<= 256 characters /^[^\p{C}]+$/
status
required

HTTP status code for this occurrence (advisory; same as response status) (RFC 9457 Section 3.1.2).

integer format: int32
>= 100 <= 599
detail

Human-readable explanation specific to this occurrence (RFC 9457 Section 3.1.4).

string
<= 500 characters
instance

URI reference identifying the specific occurrence (RFC 9457 Section 3.1.5).

string format: uri-reference
<= 2048 characters
code

Always RATE_LIMIT_EXCEEDED on this response. Wait Retry-After seconds before retrying.

string
Allowed values: RATE_LIMIT_EXCEEDED
Example
{
"type": "about:blank",
"title": "Too Many Requests",
"status": 429,
"detail": "The request rate limit has been exceeded.",
"code": "RATE_LIMIT_EXCEEDED"
}
X-RateLimit-Limit
integer format: int32
>= 1 <= 1000
Example
1000

Maximum number of requests allowed in the current window. Present when this response is rate limited.

X-RateLimit-Remaining
integer format: int32
<= 1000
Example
42

Number of requests still allowed in the current window. 0 means the next call can return 429 until the window resets.

X-RateLimit-Reset
string format: date-time
<= 29 characters
Example
2026-03-20T15:31:00.000Z

Time when the current window resets, as ISO 8601 UTC. After this time, X-RateLimit-Remaining starts over.

Retry-After
integer format: int32
>= 1 <= 3600
Example
30

HTTP Retry-After value in seconds. Wait at least this long before retrying a 429 response.

Access-Control-Allow-Origin
string
Allowed values: *
Example
*

CORS Access-Control-Allow-Origin value. Origin allowed to read this response from a browser. * means any origin may read it.

Internal server error. The server encountered an unexpected condition that prevented it from fulfilling the request.

Please try again later or contact support if the problem persists.

Media typeapplication/json
object
type

URI reference identifying the problem type. When absent, “about:blank” per RFC 9457 Section 3.1.1.

string format: uri-reference
default: about:blank <= 2048 characters
title
required

Short, human-readable summary of the problem type (RFC 9457 Section 3.1.3).

string
<= 256 characters /^[^\p{C}]+$/
status
required

HTTP status code for this occurrence (advisory; same as response status) (RFC 9457 Section 3.1.2).

integer format: int32
>= 100 <= 599
detail

Human-readable explanation specific to this occurrence (RFC 9457 Section 3.1.4).

string
<= 500 characters
instance

URI reference identifying the specific occurrence (RFC 9457 Section 3.1.5).

string format: uri-reference
<= 2048 characters
code

Always INTERNAL_ERROR on this response. Retry later. Do not retry a create in a tight loop.

string
Allowed values: INTERNAL_ERROR
Example
{
"type": "about:blank",
"title": "Internal Server Error",
"status": 500,
"detail": "The request could not be completed.",
"code": "INTERNAL_ERROR"
}
X-RateLimit-Limit
integer format: int32
>= 1 <= 1000
Example
1000

Maximum number of requests allowed in the current window. Present when this response is rate limited.

X-RateLimit-Remaining
integer format: int32
<= 1000
Example
42

Number of requests still allowed in the current window. 0 means the next call can return 429 until the window resets.

X-RateLimit-Reset
string format: date-time
<= 29 characters
Example
2026-03-20T15:31:00.000Z

Time when the current window resets, as ISO 8601 UTC. After this time, X-RateLimit-Remaining starts over.

Retry-After
integer format: int32
>= 1 <= 3600
Example
30

HTTP Retry-After value in seconds. Wait at least this long before retrying a 429 response.

Access-Control-Allow-Origin
string
Allowed values: *
Example
*

CORS Access-Control-Allow-Origin value. Origin allowed to read this response from a browser. * means any origin may read it.