> This page is for Developer Documentation.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.benchling.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.benchling.com/_mcp/server.

# Generate a token for usage with authenticating via OAuth2 in subsequent API calls.

POST https://{tenant_name}.benchling.com/api/v2/token
Content-Type: application/x-www-form-urlencoded

Generate a token

Reference: https://docs.benchling.com/docs/api/v2/benchling-api/authentication/generate-token

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Body (application/x-www-form-urlencoded)

This endpoint expects a TokenCreate.

- `grant_type` (enum, required)
  - Allowed values: `client_credentials`
- `client_id` (string, optional) — ID of client to request token for. Leave off if client ID and secret are being supplied through Authorization header.
- `client_secret` (string, optional) — Leave off if client ID and secret are being supplied through Authorization header.

## Response

### 200

Generated token

- `access_token` (string, optional)
- `expires_in` (integer, optional) — Number of seconds that token is valid for
- `token_type` (enum, optional)
  - Allowed values: `Bearer`

## Errors

### 400 Bad Request Error

Bad Request

- `error` (OAuthBadRequestErrorError, optional)

### 401 Unauthorized Error

Unauthorized

- `error` (OAuthUnauthorizedErrorError, optional)

## Types

### OAuthBadRequestErrorError

- `message` (string, optional)
- `type` (enum, optional)
  - Allowed values: `invalid_request`, `invalid_grant`, `unauthorized_client`, `unsupported_grant_type`
- `userMessage` (string, optional)

### OAuthUnauthorizedErrorError

- `message` (string, optional)
- `type` (enum, optional)
  - Allowed values: `invalid_client`
- `userMessage` (string, optional)

## Examples

**Request**

```json
{
  "grant_type": "client_credentials"
}
```

**Response**

```json
{
  "access_token": "eyJ...",
  "expires_in": 900,
  "token_type": "Bearer"
}
```

**SDK Code**

```python
import requests

url = "https://{tenant_name}.benchling.com/api/v2/token"

payload = ""
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/x-www-form-urlencoded"
}

response = requests.post(url, data=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://{tenant_name}.benchling.com/api/v2/token';
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: new URLSearchParams('')
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```