> For the complete documentation index, see [llms.txt](https://docs.viesus.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.viesus.com/reference/cloud-api/authentication.md).

# Authentication

Authenticate VIESUS Cloud API requests using the x-api-key header. Creating and managing API keys.

VIESUS Cloud authenticates every request using an API key passed as an HTTP header. There is no session, no OAuth flow, and no token expiry — just a static key on every request.

***

## Header format

```powershell
x-api-key: <your-api-key>
```

Include this header on every request to the GraphQL endpoint.

***

## Examples

**curl:**

```bash
curl -X POST https://api.viesus.cloud/graphql \
  -H "Content-Type: application/json" \
  -H "x-api-key: your-api-key-here" \
  -d '{"query": "query { credits { remainingCreditsThisPeriod } }"}'
```

**Node.js (`graphql-request`):**

```js
import { GraphQLClient } from 'graphql-request';

const client = new GraphQLClient('https://api.viesus.cloud/graphql', {
  headers: {
    'x-api-key': process.env.VIESUS_API_KEY,
  },
});
```

**Python (`gql`):**

```python
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport

transport = RequestsHTTPTransport(
    url='https://api.viesus.cloud/graphql',
    headers={'x-api-key': 'your-api-key-here'},
)
client = Client(transport=transport, fetch_schema_from_transport=True)
```

**PHP (`GuzzleHttp`):**

```php
$client = new \GuzzleHttp\Client([
    'base_uri' => 'https://api.viesus.cloud/graphql',
    'headers' => [
        'x-api-key' => 'your-api-key-here',
        'Content-Type' => 'application/json',
    ],
]);
```

***

## Creating an API key

API keys are managed in the dashboard:

→ **<https://www.viesus.cloud/app/api-keys>**

{% stepper %}
{% step %}
Log in to your account.
{% endstep %}

{% step %}
Navigate to **API Keys**.
{% endstep %}

{% step %}
Click **Create new key** and give it a descriptive name.
{% endstep %}

{% step %}
Copy and store the key securely — it is shown **only once**.
{% endstep %}
{% endstepper %}

If you lose the key, delete it and create a new one.

***

## Best practices

**Never hardcode the key in source code.** Pass it through an environment variable:

```bash
VIESUS_API_KEY="your-key-here" node server.js
```

```js
const apiKey = process.env.VIESUS_API_KEY;
if (!apiKey) throw new Error('VIESUS_API_KEY is not set');
```

**Rotate keys when team members leave** or if a key may have been exposed. Create a new key first, update all integrations, then delete the old key.

**Use separate keys per environment** (development, staging, production). This limits blast radius if a key leaks and makes it easier to track usage by environment.

***

## Verifying your key

Query the credit balance — if this returns data, your key is valid:

```graphql
query {
  credits {
    remainingCreditsThisPeriod
    usedCreditsThisPeriod
    periodStart
    periodEnd
  }
}
```

A missing or invalid key returns an authentication error in the GraphQL response.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.viesus.com/reference/cloud-api/authentication.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
