# Refresh Session

`POST /gate/refresh` · Identity & Access · Sign-in & Sessions

Exchanges a refresh token for a new Gate access JWT and a new refresh token, extending the end user's session under the project's session policy. Each refresh replaces the refresh token: store the returned `refreshToken` and refresh one call at a time per session. Presenting a refresh token that was already exchanged revokes the session and returns `K9O_SESSION_EXPIRED` (401) with `context.reason` `replay`; the session's newer refresh token is refused from then on.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `refreshToken` | string | yes | The refresh token from the sign-in or from the last refresh. Each one works once. |

```json
{
  "refreshToken": "EXAMPLE-refresh-token-not-a-real-secret-000"
}
```

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | A new access token and a new refresh token for the same session. The refresh token you sent no longer works. |
| `data.accessToken` | string | yes | A signed JWT that authenticates the end user to this project's API. Send it as `Authorization: Bearer <accessToken>`. Its subject (`sub`) is the end user's id (`eu_...`), its audience (`aud`) is the project id (`proj_...`), and its issuer is the API origin of the region that holds the end user. It lives for the project's end-user access token lifetime: 30 minutes by default, settable from 5 to 60 minutes. `expiresAt` is when it expires. It cannot be revoked early: signing out or revoking sessions stops the next refresh, but a token already issued stays valid until `expiresAt`. |
| `data.refreshToken` | string | yes | An opaque secret (43 base64url characters) that gets a new access token from `POST /@{projectSlug}/gate/refresh`. Store it securely and never send it anywhere else. It is single use: every refresh returns a new refresh token, and sending the one it replaced a second time ends the whole session. It stops working when the session ends: on sign-out, a password reset, a revoke-all, or when the project's session limits are reached (by default 30 days without a refresh, or 90 days after sign-in, whichever comes first). |
| `data.expiresAt` | string (date-time) | yes | When `accessToken` expires. Refresh before this time to keep the end user signed in. |
| `meta` | object | yes | Request metadata: cost, timing and the request and trace ids. |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_INVALID_CREDENTIALS` | The refresh token is unknown, or the end user is locked. |
| 401 | `K9O_SESSION_EXPIRED` | The session has ended and a fresh sign-in is required. `context.reason` says why: `inactive`, `max_length`, `revoked`, or `replay` (a refresh token that was already exchanged was presented again, and the session is now revoked). |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/gate/refresh' \
  -H 'Content-Type: application/json' \
  -d '{
  "refreshToken": "EXAMPLE-refresh-token-not-a-real-secret-000"
}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/gate/refresh', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
  "refreshToken": "EXAMPLE-refresh-token-not-a-real-secret-000"
}),
});
const { data, meta } = await res.json();
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.gate.refreshToken({
  refreshToken: 'EXAMPLE-refresh-token-not-a-real-secret-000'
})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.gate.refresh_token({
    "refreshToken": "EXAMPLE-refresh-token-not-a-real-secret-000"
})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Gate.RefreshToken(ctx, map[string]any{"refreshToken": "EXAMPLE-refresh-token-not-a-real-secret-000"})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.gate.refresh_token(json!({"refreshToken": "EXAMPLE-refresh-token-not-a-real-secret-000"})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.gate().refreshToken(Map.of("refreshToken", "EXAMPLE-refresh-token-not-a-real-secret-000"))
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Gate.RefreshTokenAsync(new Dictionary<string, object> { ["refreshToken"] = "EXAMPLE-refresh-token-not-a-real-secret-000" })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.gate.refresh_token({ refreshToken: "EXAMPLE-refresh-token-not-a-real-secret-000" })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->gate->refresh_token(['refreshToken' => 'EXAMPLE-refresh-token-not-a-real-secret-000'])
```

### K9o

```swift
// let k9o = try K9o.createClient(orgSlug: "playground", projectSlug: "storefront", apiKey: "k9o_…")
let result = try await k9o.gate.refreshToken({
  refreshToken: "EXAMPLE-refresh-token-not-a-real-secret-000"
})
```

### core-kotlin

```kotlin
// val k9o = createClient { orgSlug = "playground"; projectSlug = "storefront"; apiKey = "k9o_…" }
val result = k9o.gate.refreshToken({
  refreshToken: "EXAMPLE-refresh-token-not-a-real-secret-000"
})
```

### k9o (Flutter)

```dart
// final k9o = K9o.createClient(orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…');
final result = await k9o.gate.refreshToken({
  refreshToken: 'EXAMPLE-refresh-token-not-a-real-secret-000'
})
```

### @k9o/react-native

```javascript
// const k9o = createClient({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })  // RN, secure storage
const { data } = await k9o.gate.refreshToken({
  refreshToken: 'EXAMPLE-refresh-token-not-a-real-secret-000'
})
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/identity-access/refresh-session
