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

# Update API Key

> Update API key name or status

## Path Parameters

<ParamField path="organizationId" type="string" required>
  Organization ID
</ParamField>

<ParamField path="projectId" type="string" required>
  Project ID
</ParamField>

<ParamField path="id" type="string" required>
  API Key ID
</ParamField>

## Request Body

<ParamField body="name" type="string">
  Updated name for the API key
</ParamField>

<ParamField body="status" type="string">
  Updated status: `active` or `revoked`
</ParamField>

### Example Request

```json theme={null}
{
  "name": "Updated Name",
  "status": "active"
}
```

## Response

Returns the updated API Key object (without the key value).

```json theme={null}
{
  "id": "afd8012b-d81e-41c6-92cd-eed0c6cb3676",
  "projectId": "70093272-90ef-43df-807b-b66dd0a0b322",
  "name": "Updated Name",
  "status": "active",
  "createdAt": "2024-03-20T10:00:00Z",
  "updatedAt": "2024-03-22T14:00:00Z",
  "lastUsed": "2024-03-21T15:30:00Z"
}
```

<Note>
  Setting status to `revoked` will immediately prevent the key from being used. This is useful for rotating keys or responding to security incidents.
</Note>

## Error Responses

### API Key Not Found

```json theme={null}
{
  "error": {
    "code": "NOT_FOUND",
    "message": "API key not found"
  }
}
```

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PUT "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/api-keys/key123" \
    -H "Authorization: Bearer YOUR_JWT" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Updated Name",
      "status": "active"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/api-keys/key123',
    {
      method: 'PUT',
      headers: {
        'Authorization': 'Bearer YOUR_JWT',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        name: 'Updated Name',
        status: 'active'
      })
    }
  );

  const apiKey = await response.json();
  console.log(`Updated API key: ${apiKey.name}`);
  ```

  ```swift Swift theme={null}
  var request = URLRequest(url: URL(string: "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/api-keys/key123")!)
  request.httpMethod = "PUT"
  request.setValue("Bearer YOUR_JWT", forHTTPHeaderField: "Authorization")
  request.setValue("application/json", forHTTPHeaderField: "Content-Type")

  let body = ["name": "Updated Name", "status": "active"]
  request.httpBody = try JSONSerialization.data(withJSONObject: body)

  let (data, _) = try await URLSession.shared.data(for: request)
  ```

  ```kotlin Kotlin theme={null}
  val response = client.put("https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/api-keys/key123") {
      header("Authorization", "Bearer YOUR_JWT")
      contentType(ContentType.Application.Json)
      setBody(mapOf("name" to "Updated Name", "status" to "active"))
  }
  ```
</CodeGroup>
