# Authentication

How to authenticate your API requests

Requests under `/v1` and `/v1beta` need an API key. Create an account on the [home page](https://silentapi.com/), and then generate a key on the [Keys page](https://silentapi.com/keys).

The public status endpoints and the public model list need no API key. See [Overview](https://silentapi.com/docs/overview) and [OpenAI Style](https://silentapi.com/docs/openai) for details.

## API Key Security

SilentAPI stores API keys as hashes. Treat your keys like passwords, and keep them out of version control, browser code, and logs.

## Sending Your Key

Send your API key in a supported header. Query parameters are available for clients that require them.

| Name | Location | Value |
| --- | --- | --- |
| Authorization | Header | `Bearer YOUR_API_KEY` |
| x-api-key | Header | `YOUR_API_KEY` |
| x-goog-api-key | Header | `YOUR_API_KEY` |
| apiKey | Query parameter | `YOUR_API_KEY` |
| key | Query parameter | `YOUR_API_KEY` |

### Authorization Header (Recommended)

```
Authorization: Bearer YOUR_API_KEY
```

This works with the OpenAI SDK, the Anthropic SDK, curl, and most HTTP libraries.

### x-api-key Header

```
x-api-key: YOUR_API_KEY
```

The Anthropic SDK sends the `x-api-key` header. All authenticated API endpoints accept it.

### x-goog-api-key Header

```
x-goog-api-key: YOUR_API_KEY
```

The Google GenAI SDK sends the `x-goog-api-key` header. All authenticated API endpoints accept it.

### Query Parameter

```
https://api.silentapi.com/v1/chat/completions?apiKey=YOUR_API_KEY
```

```
https://api.silentapi.com/v1/chat/completions?key=YOUR_API_KEY
```

Use a query parameter only when a client cannot set a header.

Query parameter authentication puts your API key in the URL, and URLs can appear in logs, so use the Authorization header when possible.

## SDK Examples

### OpenAI SDK (Python)

```
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.silentapi.com/v1"
)

response = client.chat.completions.create(
    model="gpt-6.1-terra",
    messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)
```

### OpenAI SDK (JavaScript)

```
import OpenAI from "openai";

const client = new OpenAI({
    apiKey: "YOUR_API_KEY",
    baseURL: "https://api.silentapi.com/v1"
});

const response = await client.chat.completions.create({
    model: "gpt-6.1-terra",
    messages: [{ role: "user", content: "Hello" }]
});
const responseText = response.choices[0].message.content;
```

### Anthropic SDK (Python)

```
import anthropic

client = anthropic.Anthropic(
    api_key="YOUR_API_KEY",
    base_url="https://api.silentapi.com"
)

message = client.messages.create(
    model="claude-sonnet-5.5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}]
)
print(message.content[0].text)
```

### Google GenAI SDK (Python)

```
from google import genai

client = genai.Client(
    api_key="YOUR_API_KEY",
    http_options={"base_url": "https://api.silentapi.com"}
)

response = client.models.generate_content(
    model="gemini-4-neon",
    contents="Hello"
)
print(response.text)
```

## Per-Key Budgets

Set a monthly credit budget on each API key on the [Keys page](https://silentapi.com/keys). Requests with that API key return HTTP `402` when its budget is reached. Budgets work with activity and billing metrics on or off. With metrics off, SilentAPI keeps only the month's spend total for a key that has a budget, and nothing else about its requests.

## Key Limits

Your balance sets how many active API keys you can hold. Below 1,000 credits you can hold 5 keys, from 1,000 credits you can hold 25, and from 10,000 credits you can hold 100. If your balance falls to a lower level, your keys stay active, but you cannot create new keys until you are under the new limit.

Contact [contact@silentapi.com](mailto:contact@silentapi.com) if you need more keys.

## Two-Factor Authentication

Add an authenticator app, email codes, or PGP codes in [Settings](https://silentapi.com/settings). Turning on the first method also creates recovery codes, and each recovery code works once. When more than one method is on, you choose which one to use each time.

The level sets which actions ask for a code. Signing in always asks for one.

| Level | Asks for a code before |
| --- | --- |
| Sign-in | Changing two-factor settings and deleting the account |
| Account | Everything in Sign-in, plus changing your email, password, or username |
| Everything | Every sensitive action, including creating, changing, or deleting API keys and clearing history |

Source: https://silentapi.com/docs/authentication
