# get\_\_apikeys

## Request

**Endpoint**: `GET /apikeys`

Retrieves a list of available provider API keys, which can be reused when creating new storage units or configuring AI models. This endpoint requires a valid session token.

### Query Parameters

| Field         | Type   | Required | Description                                                                                                                                  |
| ------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `workspaceId` | string | Optional | The unique identifier of the workspace to filter API keys. If omitted, returns API keys across the organization that the user has access to. |

### Request Example

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X GET "https://backend.flashback.tech/apikeys?workspaceId=workspace-uuid" \
  -H "Authorization: Bearer <your-session-token>" \
  -H "Content-Type: application/json"
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch("https://backend.flashback.tech/apikeys?workspaceId=workspace-uuid", {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer <your-session-token>',
    'Content-Type': 'application/json'
  }
});
const data = await response.json();
console.log(data);
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://backend.flashback.tech/apikeys"
params = {"workspaceId": "workspace-uuid"}
headers = {
    "Authorization": "Bearer <your-session-token>",
    "Content-Type": "application/json"
}

response = requests.get(url, headers=headers, params=params)
print(response.json())
```

{% endtab %}

{% tab title="Go" %}

```go
import (
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	url := "https://backend.flashback.tech/apikeys?workspaceId=workspace-uuid"
	req, _ := http.NewRequest("GET", url, nil)
	req.Header.Add("Authorization", "Bearer <your-session-token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)
	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(string(body))
}
```

{% endtab %}
{% endtabs %}

***

## Response

### Response Fields (GetProviderApiKeysResponse)

| Field     | Type    | Description                                            |
| --------- | ------- | ------------------------------------------------------ |
| `success` | boolean | Indicates whether the request was successful (`true`). |
| `apiKeys` | array   | A list of API key objects (`ProviderApiKeyDTO`).       |

#### ProviderApiKeyDTO

| Field          | Type                | Description                                                           |
| -------------- | ------------------- | --------------------------------------------------------------------- |
| `id`           | string              | Unique identifier for the API key.                                    |
| `key`          | string              | The public access key or identifier for the provider.                 |
| `endpoint`     | string \| undefined | The endpoint URL of the provider (if applicable).                     |
| `region`       | string \| undefined | The region of the provider (if applicable).                           |
| `provider`     | string              | The name or enum value of the provider (e.g., `AWS`, `GCP`, `AZURE`). |
| `createdAt`    | string              | ISO 8601 timestamp of when the API key was created.                   |
| `bucket_count` | number \| undefined | The total number of active storage units/buckets using this API key.  |
| `aillm_count`  | number \| undefined | The total number of active AI models using this API key.              |

### Response Example (200 OK)

```json
{
  "success": true,
  "apiKeys": [
    {
      "id": "e421a8cd-...",
      "key": "AKIAIOSFODNN7EXAMPLE",
      "endpoint": "s3.us-east-1.amazonaws.com",
      "region": "us-east-1",
      "provider": "AWS",
      "createdAt": "2024-03-08T12:00:00.000Z",
      "bucket_count": 2,
      "aillm_count": 0
    },
    {
      "id": "f8a91b2c-...",
      "key": "some-other-key",
      "provider": "GCP",
      "createdAt": "2024-03-05T08:30:00.000Z",
      "bucket_count": 1,
      "aillm_count": 1
    }
  ]
}
```

***

## Error Responses

### 401 Unauthorized

Returned when the session token is missing, invalid, or the user cannot be validated.

```json
{
  "success": false,
  "message": "User not found or not validated"
}
```

### 403 Forbidden

Returned when the user does not have permission to read buckets or API keys in the specified workspace.

```json
{
  "success": false,
  "message": "Insufficient permissions to read API keys in this workspace"
}
```

### 500 Internal Server Error

Returned when an unexpected server error occurs.

```json
{
  "success": false,
  "apiKeys": [],
  "message": "Internal server error"
}
```
