> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tensorone.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Secure your API requests with TensorOne authentication methods

## Overview

TensorOne API uses API key authentication to secure all requests. Each API key has specific permissions and can be scoped to different resources within your account.

## API Key Types

### Read Keys

* **Purpose**: Read-only access to your resources
* **Use Cases**: Monitoring dashboards, analytics, status checks
* **Permissions**: GET requests only

### Read & Write Keys

* **Purpose**: Full access to create, modify, and delete resources
* **Use Cases**: Automated deployments, infrastructure management
* **Permissions**: All HTTP methods (GET, POST, PUT, DELETE)

### Service Keys

* **Purpose**: Specific service access (AI models, training jobs)
* **Use Cases**: Production AI applications, specialized workflows
* **Permissions**: Limited to specific service endpoints

## Authentication Header

Include your API key in the Authorization header of every request:

```http
Authorization: Bearer tpo_live_1234567890abcdefghijklmnopqrstuvwxyz
```

## Creating API Keys

### Via Web Console

1. Navigate to **Settings > API Keys**
2. Click **Create API Key**
3. Select permissions: Read, Read & Write, or Service-specific
4. Add optional description and expiration date
5. Copy the key immediately (shown only once)

### Via API

```bash
curl -X POST "https://api.tensorone.ai/v2/auth/api-keys" \
  -H "Authorization: Bearer YOUR_ADMIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production API Key",
    "permissions": ["read", "write"],
    "expiresAt": "2024-12-31T23:59:59Z",
    "scopes": ["endpoints", "clusters"]
  }'
```

## Key Management

### List API Keys

```bash
curl -X GET "https://api.tensorone.ai/v2/auth/api-keys" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

### Revoke API Key

```bash
curl -X DELETE "https://api.tensorone.ai/v2/auth/api-keys/key_1234567890" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

### Rotate API Key

```bash
curl -X POST "https://api.tensorone.ai/v2/auth/api-keys/key_1234567890/rotate" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Environment Variables

Store your API keys securely using environment variables:

```bash
# Production
export TENSORONE_API_KEY="tpo_live_1234567890abcdef..."

# Development
export TENSORONE_API_KEY="tpo_test_1234567890abcdef..."
```

## SDKs Authentication

### Python SDK

```python
import tensorone

# Method 1: Environment variable
client = tensorone.Client()  # Reads TENSORONE_API_KEY

# Method 2: Direct key
client = tensorone.Client(api_key="tpo_live_...")
```

### JavaScript SDK

```javascript
import TensorOne from "tensorone-sdk";

// Method 1: Environment variable
const client = new TensorOne(); // Reads TENSORONE_API_KEY

// Method 2: Direct key
const client = new TensorOne({
    apiKey: "tpo_live_...",
});
```

## Security Best Practices

> [!WARNING]
>
> **Never expose API keys in client-side code, public repositories, or logs.**

### ✅ Do

* Store keys in environment variables
* Use least-privilege permissions
* Rotate keys regularly
* Monitor key usage
* Set expiration dates
* Use different keys for different environments

### ❌ Don't

* Hardcode keys in source code
* Share keys via email or chat
* Use production keys in development
* Grant excessive permissions
* Ignore key rotation

## Error Responses

### 401 Unauthorized

```json
{
    "error": "UNAUTHORIZED",
    "message": "Invalid or missing API key",
    "code": 401
}
```

### 403 Forbidden

```json
{
    "error": "FORBIDDEN",
    "message": "API key lacks required permissions",
    "code": 403,
    "required_permission": "endpoints:write"
}
```

### 429 Rate Limited

```json
{
    "error": "RATE_LIMITED",
    "message": "API key rate limit exceeded",
    "code": 429,
    "retry_after": 60
}
```

## Key Scopes

Restrict API keys to specific resources:

* `accounts`: Account management
* `clusters`: GPU cluster operations
* `endpoints`: Serverless endpoints
* `training`: Model training jobs
* `billing`: Payment and usage data
* `ai`: AI service access
* `webhooks`: Webhook management

## Testing Authentication

Verify your API key works:

```bash
curl -X GET "https://api.tensorone.ai/v2/auth/verify" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Response:

```json
{
    "valid": true,
    "key_id": "key_1234567890",
    "permissions": ["read", "write"],
    "scopes": ["endpoints", "clusters"],
    "expires_at": "2024-12-31T23:59:59Z"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.