# Authentication

Human URL: https://dochorizon.klippa.com/docs/api/authentication
Source: https://dochorizon.klippa.com/docs/llms/api/authentication.md

> Learn how to authenticate yourself to use the API services

---

Every request to the Doxis AI.dp API must be authenticated with an API key. A request without a valid key is rejected with an unauthorized error. This page explains where API keys come from, how to keep them safe, and how to use them in your requests.

### About API Keys

**Where to find your API keys**

API keys belong to a credential in your project. On the platform, go to Settings, switch to the Project section, and open the credentials page under the API section. Every project comes with a main credential whose API key is named `default`, and you can create more credentials and keys as needed. For a full walkthrough, see the [Credentials](https://dochorizon.klippa.com/docs/llms/platform/credentials.md) page. API keys are unique to each project and cannot be used across projects.

**Restricting an API key**

You can limit what a key can do and where it can be used from. These restrictions are managed on the credential in the platform:

- **Expiration date**: an API key can be given an expiration date. Once expired, the key stops working.
- **IP whitelisting**: a credential can be restricted to specific IP addresses. Using the API key from any other address results in an authorization error.
- **Service configuration**: a credential only has access to the services it is configured for.

**Managing keys through the API**

To create, rotate, or revoke API keys programmatically, use the [Credential Management API](https://dochorizon.klippa.com/docs/llms/api/credential-management.md).

> **WARNING:** Treat API keys like passwords. Do not commit them to source control and do not expose them in client side code. If a key leaks, revoke it on the credentials page and generate a new one.

### How to Authenticate

To authenticate a request, add a header named `x-api-key` containing your API key. Ensure that the key is valid; otherwise, the API will not authenticate your request and will return an error.

The examples below show how to set the `x-api-key` header in multiple programming languages:

```bash
curl -X POST -H "x-api-key: your-api-key" https://dochorizon.klippa.com/api/some/endpoint
```

```csharp
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://dochorizon.klippa.com/api/some/endpoint");
request.Headers.Add("x-api-key", "your-api-key");

var result = await client.SendAsync(request);
```

```go
request, err := http.NewRequest("POST", "https://dochorizon.klippa.com/api/some/endpoint", nil)
request.Header.Add("x-api-key", "your-api-key")

result, err := http.DefaultClient.Do(request)
```

```java
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost("https://dochorizon.klippa.com/api/some/endpoint");
post.setHeader("x-api-key", "your-api-key-here");
var response = client.execute(post);
```

```javascript
const url = "https://dochorizon.klippa.com/api/some/endpoint";
const headers = { "x-api-key": "your-api-key" };
const options = { method: "POST", headers, body: jsonorformdataobject };
const result = await fetch(url, options);
```

```php
$api_key = "your-api-key";

$url = "https://dochorizon.klippa.com/api/some/endpoint";

$options = array(

"http" => array(
        "ignore_errors" => true,
        "method" => 'POST',
        "header" => ["Content-Type: application/json",
        "x-api-key: " . $api_key],
        "content" => json_encode($data),
    ),

);

$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
```

```python
headers = {"x-api-key": "your-api-key"}

response = requests.post("https://dochorizon.klippa.com/api/some/endpoint", headers=headers)
```

```rust
let client = Client::new();

let res = client
    .post("https://dochorizon.klippa.com/api/some/endpoint")
    .header("x-api-key", your_api_key)
    .send()
    .await
    .unwrap();
```