> This page is part of EVVA for Developers (https://developers.evvahub.com), the documentation of the EVVA Partner API. The API is in developer preview and the SDK packages are not yet published: do not suggest installing them. Index: https://developers.evvahub.com/llms.txt

# Requesting tokens

Every call to the Partner API carries an access token. Your server gets one from the token endpoint with the OAuth 2.0 `client_credentials` grant, authenticating as the application with either a **client secret** or a **private key** (`private_key_jwt`).

```http
POST https://api.evvahub.com/partner/v1/oauth/token
```

> **Info**
>
> There is no refresh token. When a token is about to expire, request a new one with the same credentials. The official SDKs do this for you.

## The request

Send the parameters in the request **body**, as `application/x-www-form-urlencoded` (the OAuth standard) or as `application/json` with the same names.

| Parameter               | Required                  | Value                                                                                                                                                                      |
| ----------------------- | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `grant_type`            | Yes                       | `client_credentials`                                                                                                                                                       |
| `scope`                 | No                        | Space-separated scopes, each one the application is allowed. Omit it to get every scope the application is allowed right now. See [Narrowing a token](#narrowing-a-token). |
| `client_id`             | With `client_secret_post` | Your client ID (`evpc_live_…` or `evpc_test_…`). Optional with the other two methods; if you send it, it must name the same client.                                        |
| `client_secret`         | With `client_secret_post` | Your client secret.                                                                                                                                                        |
| `client_assertion_type` | With `private_key_jwt`    | `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`                                                                                                                   |
| `client_assertion`      | With `private_key_jwt`    | The signed JWT described in [Authenticating with a private key](#authenticating-with-a-private-key).                                                                       |

The endpoint is strict about the shape of the request, and refuses it with `invalid_request` when:

* a recognised parameter appears more than once;
* a recognised parameter is sent in the URL query string — credentials never travel in a URL;
* the request uses more than one authentication method (for example an `Authorization: Basic` header **and** a `client_secret` in the body);
* the content type is neither of the two above.

Parameters the endpoint does not recognise are ignored, and a parameter sent with an empty value counts as not sent. Keep the body under 16 KiB.

## Authenticating with a client secret

You get the client secret once, when the application is created or its secret is rotated in the Partner Hub. EVVA keeps only a digest of it and can never show it again.

There are two ways to present it:

| Method                | How                                                                                                                                                                                                                                                                                |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `client_secret_basic` | `Authorization: Basic base64(client_id ":" client_secret)`, each half form-URL-encoded before the base64 step, as RFC 6749 (section 2.3.1) requires. EVVA client IDs and secrets contain only URL-safe characters, so the encoding changes nothing in practice. The SDKs' default. |
| `client_secret_post`  | `client_id` and `client_secret` as body parameters.                                                                                                                                                                                                                                |

**`cURL`**

```bash title="cURL"
# client_secret_basic: curl -u builds the Basic header
curl -sS https://api.evvahub.com/partner/v1/oauth/token \
  -u "$EVVA_CLIENT_ID:$EVVA_CLIENT_SECRET" \
  -d grant_type=client_credentials

# client_secret_post: the same credentials in the body
curl -sS https://api.evvahub.com/partner/v1/oauth/token \
  -d grant_type=client_credentials \
  -d client_id="$EVVA_CLIENT_ID" \
  -d client_secret="$EVVA_CLIENT_SECRET"
```

**`TypeScript`**

```typescript title="TypeScript"
import { EvvaPartnerClient } from '@evvahub/partner-sdk';

// The SDK requests, caches and renews the token for every call you make.
const evva = new EvvaPartnerClient({
  baseUrl: 'https://api.evvahub.com',
  credentials: {
    method: 'client_secret_basic', // or 'client_secret_post'
    clientId: process.env.EVVA_CLIENT_ID!,
    clientSecret: process.env.EVVA_CLIENT_SECRET!,
  },
});
```

**`Python`**

```python title="Python"
import os
from evva_partner import ClientSecretBasic, EvvaPartnerClient  # or ClientSecretPost

client = EvvaPartnerClient(
    base_url="https://api.evvahub.com",
    auth=ClientSecretBasic(os.environ["EVVA_CLIENT_ID"], os.environ["EVVA_CLIENT_SECRET"]),
)
```

**`Go`**

```go title="Go"
// With a secret the SDK uses client_secret_basic;
// set AuthMethod: evvapartner.AuthClientSecretPost for the body form.
client, err := evvapartner.NewClient(evvapartner.Config{
	BaseURL:      "https://api.evvahub.com",
	ClientID:     os.Getenv("EVVA_CLIENT_ID"),
	ClientSecret: evvapartner.Secret(os.Getenv("EVVA_CLIENT_SECRET")),
})
if err != nil {
	log.Fatal(err)
}
```

**`PHP`**

```php title="PHP"
use Evva\Partner\Auth\ClientCredentials;
use Evva\Partner\PartnerClient;

$evva = new PartnerClient(
    baseUrl: 'https://api.evvahub.com',
    credentials: ClientCredentials::secretBasic(getenv('EVVA_CLIENT_ID'), getenv('EVVA_CLIENT_SECRET')),
    // or ClientCredentials::secretPost(...)
);
```

## Authenticating with a private key

With `private_key_jwt` no shared secret ever leaves your infrastructure. You register the **public** half of a key pair on the application, keep the private key on your server, and sign a short-lived JWT (the *client assertion*) for every token request.

```mermaid
sequenceDiagram
    autonumber
    participant Hub as Partner Hub
    participant App as Your server
    participant Token as Token endpoint
    participant API as Partner API
    App->>App: Create a key pair (RS256 or ES256)
    App->>Hub: Register the PUBLIC key with a key ID (kid)
    App->>App: Sign an assertion: iss = sub = client_id, aud = token URL, exp ≤ 5 min, new jti, kid
    App->>Token: POST grant_type=client_credentials + client_assertion
    Token->>Token: Verify signature with the registered key, check claims, spend the jti
    Token-->>App: {access_token: evpa_live_…, expires_in: 900}
    App->>API: Authorization: Bearer evpa_live_…
```

### 1. Create a key pair and register the public key

EVVA accepts two algorithms:

| Algorithm | Key                     |
| --------- | ----------------------- |
| `RS256`   | RSA, at least 2048 bits |
| `ES256`   | EC on the P-256 curve   |

```bash
# ES256 key pair: keep evva-app.pem secret, register the public key
openssl ecparam -name prime256v1 -genkey -noout | openssl pkcs8 -topk8 -nocrypt -out evva-app.pem
openssl pkey -in evva-app.pem -pubout -out evva-app.pub.pem
```

In the Partner Hub, open **Integrations → Applications →** your application **→ Credentials**, and under **Public keys (private_key_jwt)** use **Add a public key**: choose the algorithm, give a key ID (`kid`), paste the public key as a JWK, and optionally set **Valid until**.

* The key ID is 1–128 characters of `A–Z a–z 0–9 . _ -`. Leave it empty to use the JWK's own `kid`.
* A key ID is unique within the application, including keys you have revoked, so a revoked key's ID cannot be reused.
* Upload only the public key. A JWK that carries private key material is refused outright.
* An application holds at most **5 active keys** at a time, which leaves room for a rollover.

### 2. Build the assertion

The assertion is a compact JWS (three dot-separated parts) signed with your private key.

**Header**

| Member                                                  | Rule                                                                                                                                                     |
| ------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `alg`                                                   | `RS256` or `ES256`, and the same algorithm the key was registered with. Anything else — `none`, any `HS*`, `PS*`, `EdDSA` — is refused.                  |
| `kid`                                                   | The registered key ID. Recommended. Without it, the application must have exactly one usable key for that algorithm, otherwise the assertion is refused. |
| `typ`                                                   | Optional. If present: `JWT`, `client-authentication+jwt` or `application/jwt`.                                                                           |
| `jwk`, `jku`, `x5u`, `x5c`, `crit`, `b64`, `zip`, `enc` | Not allowed. Only keys registered on the application can verify an assertion.                                                                            |

**Claims**

| Claim | Required | Rule                                                                                                                                                                                                                                                                                                                 |
| ----- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `iss` | Yes      | Your client ID.                                                                                                                                                                                                                                                                                                      |
| `sub` | Yes      | Your client ID.                                                                                                                                                                                                                                                                                                      |
| `aud` | Yes      | The token endpoint URL, exactly: `https://api.evvahub.com/partner/v1/oauth/token`. A string, or an array that contains it. The match is exact — no trailing slash, no other spelling. [`GET /partner/v1/app/capabilities`](https://developers.evvahub.com/api-reference/application/get-application-capabilities) returns the value as `authentication.tokenEndpoint`. |
| `exp` | Yes      | Expiry, in seconds since the epoch. At most **5 minutes** ahead.                                                                                                                                                                                                                                                     |
| `iat` | No       | Issued-at. Not in the future; when present, `exp − iat` must not exceed 5 minutes.                                                                                                                                                                                                                                   |
| `nbf` | No       | Not-before. Not in the future.                                                                                                                                                                                                                                                                                       |
| `jti` | Yes      | A unique ID, 1–256 visible ASCII characters. Each `jti` is accepted **once** per client; a repeat is refused.                                                                                                                                                                                                        |

EVVA tolerates **60 seconds** of clock difference on `exp`, `iat` and `nbf`. Keep your servers' clocks synchronised.

**`Assertion header and claims, before signing`**

```json title="Assertion header and claims, before signing"
{ "alg": "ES256", "typ": "JWT", "kid": "key-2026-12" }

{
  "iss": "evpc_live_YOUR_CLIENT_ID",
  "sub": "evpc_live_YOUR_CLIENT_ID",
  "aud": "https://api.evvahub.com/partner/v1/oauth/token",
  "iat": 1795000000,
  "exp": 1795000060,
  "jti": "5f0c8a52-6b0e-4d55-9a8e-3f1d2c7b9e41"
}
```

### 3. Request the token

**`cURL`**

```bash title="cURL"
# $ASSERTION holds the signed JWT from step 2
curl -sS https://api.evvahub.com/partner/v1/oauth/token \
  -d grant_type=client_credentials \
  -d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer \
  -d client_assertion="$ASSERTION"
```

**`TypeScript`**

```typescript title="TypeScript"
import { readFileSync } from 'node:fs';
import { EvvaPartnerClient } from '@evvahub/partner-sdk';

// The SDK signs a fresh assertion (random jti, kid in the header) for every token request.
const evva = new EvvaPartnerClient({
  baseUrl: 'https://api.evvahub.com',
  credentials: {
    method: 'private_key_jwt',
    clientId: process.env.EVVA_CLIENT_ID!,
    privateKey: readFileSync('evva-app.pem', 'utf8'),
    keyId: 'key-2026-12',
    algorithm: 'ES256',
  },
});
```

**`Python`**

```python title="Python"
import os
from evva_partner import EvvaPartnerClient, PrivateKeyJwt

with open("evva-app.pem", "rb") as f:
    private_key = f.read()

client = EvvaPartnerClient(
    base_url="https://api.evvahub.com",
    auth=PrivateKeyJwt(os.environ["EVVA_CLIENT_ID"], private_key, key_id="key-2026-12", algorithm="ES256"),
)
```

**`Go`**

```go title="Go"
// Reads EVVA_BASE_URL, EVVA_CLIENT_ID, EVVA_PRIVATE_KEY_FILE and EVVA_KEY_ID.
// With a private key the SDK uses private_key_jwt. Config.PrivateKey also accepts
// any crypto.Signer, so the key can stay in a KMS or HSM.
cfg, err := evvapartner.ConfigFromEnv()
if err != nil {
	log.Fatal(err)
}
client, err := evvapartner.NewClient(cfg)
if err != nil {
	log.Fatal(err)
}
```

**`PHP`**

```php title="PHP"
use Evva\Partner\Auth\AssertionAlgorithm;
use Evva\Partner\Auth\ClientCredentials;
use Evva\Partner\PartnerClient;

$evva = new PartnerClient(
    baseUrl: 'https://api.evvahub.com',
    credentials: ClientCredentials::privateKeyJwt(
        getenv('EVVA_CLIENT_ID'),
        file_get_contents('/run/secrets/evva-app.pem'),
        'key-2026-12',
        AssertionAlgorithm::ES256,
    ),
);
```

## The response

A successful request returns `200` with the token. Every response from the token endpoint — success or error — carries `Cache-Control: no-store` and `Pragma: no-cache`.

**`200 OK`**

```json title="200 OK"
{
  "access_token": "evpa_live_…",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "read:messages write:messages write:messages:automated"
}
```

| Field          | Meaning                                                                                                                                              |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `access_token` | An opaque token: `evpa_live_` (live application) or `evpa_test_` (sandbox application) followed by 43 characters. Do not parse it, and never log it. |
| `token_type`   | Always `Bearer`.                                                                                                                                     |
| `expires_in`   | Lifetime in seconds — **900 (15 minutes)**. Read the value rather than hard-coding it.                                                               |
| `scope`        | The scopes this token carries, space-separated.                                                                                                      |

Send the token on every API call:

```http
Authorization: Bearer evpa_live_…
```

## Narrowing a token

A token can only ever carry scopes the application is allowed. Use `scope` to ask for less than that — for example a worker that only reads conversations:

```bash
curl -sS https://api.evvahub.com/partner/v1/oauth/token \
  -u "$EVVA_CLIENT_ID:$EVVA_CLIENT_SECRET" \
  -d grant_type=client_credentials \
  -d scope="read:messages read:subscribers"
```

* Scopes are separated by spaces. Duplicates are merged.
* If **any** requested scope is not one the application is allowed, the whole request is refused with `invalid_scope`. Nothing is silently dropped.
* A token carries at most 64 scopes.
* Without `scope`, the token carries every scope the application is allowed at that moment.

The SDKs take the same list as an option: `scopes` (TypeScript, Python, PHP) or `Scopes` (Go).

Holding a scope on the token is only one condition; what the application may actually do for each creator also depends on its grants and the creator's consent. See [Scopes and grants](/authentication/scopes).

## Errors

Errors follow RFC 6749 (section 5.2): a JSON body with `error` and `error_description`.

**`401 Unauthorized`**

```json title="401 Unauthorized"
{
  "error": "invalid_client",
  "error_description": "Client authentication failed."
}
```

| `error`                   | Status | When                                                                                                                                                                                                                                                                                                                                             |
| ------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `invalid_request`         | 400    | The request is malformed: wrong content type, unreadable body, a duplicated parameter, a parameter in the URL, more than one authentication method, `client_secret` without `client_id`, or only half of the assertion pair. `error_description` says which.                                                                                     |
| `invalid_client`          | 401    | Client authentication failed, for any reason: unknown client, wrong or retired secret, unknown or revoked key, bad signature, wrong `aud`, expired assertion, reused `jti`. The body is the same in every case, on purpose. When you used HTTP Basic, the response also carries `WWW-Authenticate: Basic realm="evva-partner", charset="UTF-8"`. |
| `unauthorized_client`     | 400    | The credentials are valid, but the application may not get a token now: it is waiting for EVVA's review, it is disabled, or your agency is suspended.                                                                                                                                                                                            |
| `unsupported_grant_type`  | 400    | The `client_credentials` grant is not available.                                                                                                                                                                                                                                                                                                 |
| `invalid_scope`           | 400    | `scope` is malformed, names more than 64 scopes, or names a scope the application is not allowed.                                                                                                                                                                                                                                                |
| `temporarily_unavailable` | 503    | EVVA could not verify the request right now. Nothing was issued. Retry after the `Retry-After` header (5 seconds).                                                                                                                                                                                                                               |

> **Tip**
>
> `invalid_client` deliberately does not say what was wrong. Check, in order: the client ID was copied whole, the secret is the current one, the key ID matches a registered active key, `aud` is the exact token endpoint URL, `exp` is no more than 5 minutes ahead, `jti` is new, and your server clock is synchronised.

## Token lifetime

An access token lives **15 minutes** (`expires_in: 900`). There is no refresh token: request a new token before the current one expires. The SDKs renew a token 60 seconds before it expires and share one request between concurrent callers.

A token stops working before its expiry when it is revoked, when the application is disabled or revoked, or when your agency is suspended. A request with a token that is expired, revoked or unknown gets:

```http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="evva-partner", error="invalid_token"
```

```json
{ "code": "INVALID_TOKEN", "error": "The access token is not valid", "requestId": "…" }
```

Request a new token and retry. If the new token request is refused, its error tells you why.

## Revoking a token

Revoke a token you no longer need — for example when a worker shuts down — at the revocation endpoint ([RFC 7009](https://www.rfc-editor.org/rfc/rfc7009)):

```http
POST https://api.evvahub.com/partner/v1/oauth/revoke
```

| Parameter             | Required | Value                                                                                               |
| --------------------- | -------- | --------------------------------------------------------------------------------------------------- |
| `token`               | Yes      | The access token to revoke.                                                                         |
| `token_type_hint`     | No       | A hint only; it does not change the result.                                                         |
| Client authentication | Yes      | Exactly as at the token endpoint: `client_secret_basic`, `client_secret_post` or `private_key_jwt`. |

The answer is `200` with an empty body whenever the request itself is valid — whether the token was revoked now, was already revoked or expired, is unknown, or belongs to another application (which is left untouched). An application can only revoke its own tokens, and can do so even while it is disabled. Errors are `400 invalid_request`, `401 invalid_client` and `503 temporarily_unavailable`, as above.

Revocation takes effect from the next request. Realtime connections opened with the token are closed (`SESSION_REVOKED`, then close code `4401`).

**`cURL`**

```bash title="cURL"
curl -sS https://api.evvahub.com/partner/v1/oauth/revoke \
  -u "$EVVA_CLIENT_ID:$EVVA_CLIENT_SECRET" \
  -d token="$TOKEN"
```

**`TypeScript`**

```typescript title="TypeScript"
import { ClientCredentialsTokenProvider, EvvaPartnerClient } from '@evvahub/partner-sdk';

const tokens = new ClientCredentialsTokenProvider({
  baseUrl: 'https://api.evvahub.com',
  credentials: {
    method: 'client_secret_basic',
    clientId: process.env.EVVA_CLIENT_ID!,
    clientSecret: process.env.EVVA_CLIENT_SECRET!,
  },
});
const evva = new EvvaPartnerClient({ baseUrl: 'https://api.evvahub.com', tokenProvider: tokens });

// … at shutdown: revokes the cached token
await tokens.revoke();
```

**`Python`**

```python title="Python"
# at shutdown: revokes the cached token
client.tokens.revoke()
```

**`Go`**

```go title="Go"
// at shutdown: revokes the cached token
if ts, ok := client.TokenSource().(*evvapartner.ClientCredentialsTokenSource); ok {
	if err := ts.Revoke(ctx); err != nil {
		log.Print(err)
	}
}
```

**`PHP`**

```php title="PHP"
// at shutdown: revokes the cached token
$evva->tokenProvider->revoke();
```

## Rotating credentials

Credentials are managed in the Partner Hub under **Integrations → Applications →** your application **→ Credentials**. Only the agency owner can change them; team leads can see them.

### Client secret

**Rotate secret** creates a new secret, shows it once, and retires the current one after an overlap you choose under **Keep the current secret working for**: *End it now*, *1 hour*, *24 hours (default)*, *3 days* or *7 days (maximum)*.

#### Rotate

Rotate the secret in the Partner Hub and store the new value in your secret manager.

#### Roll it out

Deploy the new secret to every server within the overlap. During the overlap both secrets authenticate.

#### Let the old one lapse

When the overlap ends, only the new secret works.

At most two secrets work at once: rotating again during an overlap ends the older overlap immediately. After a secret is created, the Hub shows only its last four characters.

### Public keys

Because an application can hold up to five active keys, you rotate a key with no downtime: add the new public key with a new key ID, switch your signer to the new private key and `kid`, then revoke the old key in the Hub. Assertions signed with a revoked key are refused from that moment. A key with **Valid until** set stops authenticating at that time.

```mermaid
sequenceDiagram
    autonumber
    participant App as Your server
    participant Hub as Partner Hub
    participant Token as Token endpoint
    App->>Hub: Add the new public key (new kid)
    Note over App,Token: Overlap: both keys are active
    App->>Token: Assertion signed with the OLD key (kid old)
    Token-->>App: access token
    App->>App: Switch the signer to the new private key and kid
    App->>Token: Assertion signed with the NEW key (kid new)
    Token-->>App: access token
    App->>Hub: Revoke the old key
    App->>Token: Assertion signed with the old key
    Token-->>App: 401 invalid_client
```

> **Warning**
>
> Rotating a secret or revoking a key does not end access tokens already issued with it: they keep working until they expire, at most 15 minutes later. If a credential leaked, also revoke the tokens issued with it, or disable the application in the Hub, which revokes all of its tokens at once.

#### Can I send client_id together with an assertion?

Yes. With `private_key_jwt` the `client_id` parameter is optional; if you send it, it must equal the assertion's `sub`, otherwise authentication fails. With HTTP Basic, a `client_id` in the body must equal the one in the header.

#### Why was my assertion refused the second time?

Each `jti` is accepted once per client for as long as the assertion could be valid. Sign a new assertion, with a new random `jti`, for every token request — including retries.

#### Does a sandbox client work for live creators?

No. A sandbox application's client ID starts with `evpc_test_` and its tokens with `evpa_test_`; it acts only in the [sandbox](/sandbox). A live application uses `evpc_live_` and `evpa_live_`.

#### Can I see my access tokens in the Partner Hub?

No. Access tokens are never shown in the Hub. To end one, revoke it with the revocation endpoint, or disable the application.

## Next steps

#### [Scopes and grants](/authentication/scopes)

What each scope allows, and how grants and consent narrow it per creator.

#### [Authentication overview](/authentication/overview)

How applications, credentials, tokens and access fit together.

#### [Rate limits and quotas](/authentication/rate-limits)

How much an application can call, and what a 429 means.

#### [SDKs](/sdks/overview)

Token handling, retries and events, done for you in four languages.