> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/web-api/authentication.md).

# Authentication

Learn how to authenticate requests to Oxylabs Web API endpoints.

The Oxylabs Web API uses the **API key as Bearer Token** for authentication. Every HTTP request sent to the API must include your API key in the `Authorization` request header.

```http
Authorization: Bearer YOUR_API_KEY
```

{% hint style="warning" %}
**Bearer scheme is mandatory.** The API backend parses the `Authorization` header for a `Bearer` prefix. Standard HTTP Basic Authentication (`Authorization: Basic ...`) is not accepted on any `/v1/scrape` or `/v1/search` requests and will return a `401 Unauthorized` status code.
{% endhint %}

To verify your credentials, you can submit a minimal search query:

```bash
curl https://webapi.oxylabs.io/v1/search \
  -H "Authorization: Bearer $OXYLABS_WEB_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"query": "oxylabs"}'
```

## Getting a key

1. Log in to the [Oxylabs dashboard](https://dashboard.oxylabs.io).
2. Create a **Web API** instance.
3. Generate an API key on that instance.
4. Export it where your application reads it (e.g. your OS terminal or the CLI terminal of the project workspace):

```bash
export OXYLABS_WEB_API_KEY=your_api_key_here
```

## Troubleshooting `401 Unauthorized` errors

An authentication failure returns an HTTP `401` status without a JSON response body. The status code itself indicates that the request was rejected.

<table><thead><tr><th width="219">Scenario</th><th>Cause</th><th>Solution</th></tr></thead><tbody><tr><td><code>401</code> on new integration</td><td>Key missing, header misspelled, or trailing whitespace/newlines from copy-pasting.</td><td>Re-copy the key from the <a href="https://dashboard.oxylabs.io">dashboard</a>. Check for trailing newlines or shell quote mangling (<code>.strip()</code>).</td></tr><tr><td><code>401</code> with valid key format</td><td>Key belongs to a different Oxylabs product.</td><td>Confirm the key was generated specifically on a Web API instance in the dashboard.</td></tr><tr><td><code>401</code> on previously working key</td><td>Key has been revoked, replaced, or deleted.</td><td>Generate a new key on your active instance.</td></tr><tr><td><code>401</code> across all requests</td><td>The account subscription or instance is disabled.</td><td>Contact <a href="mailto:support@oxylabs.io">Oxylabs support</a> to re-enable the account.</td></tr></tbody></table>

## Recommended practices for manual integrations

{% hint style="warning" %}
An API key is a spending credential. Anyone holding it can consume your account quota.
{% endhint %}

<table data-header-hidden><thead><tr><th width="154"></th><th></th></tr></thead><tbody><tr><td><strong>Environment variables</strong></td><td>Store keys in environment variables (<code>OXYLABS_WEB_API_KEY</code>) or dedicated secret managers (e.g., AWS Secrets Manager, HashiCorp Vault, etc.). Avoid hardcoding keys in source code.</td></tr><tr><td><strong>Key isolation</strong></td><td>Use separate Web API instances for development, staging, and production to isolate product credit consumption and allow independent credential rotation.</td></tr></tbody></table>


---

# 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://developers.oxylabs.io/products/web-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.
