# Authentication

AccuWeather APIs use API key-based authentication to secure access to weather data. Every request to the API must include a valid API key in the `Authorization` header.

## Get your API key

Your API key is available in your account dashboard.

1. [Sign up](/signin) for a free AccuWeather developer account or sign in if you already have an account.
2. Navigate to your [subscriptions](/subscriptions) page.
3. Copy your API key from the dashboard.

Your API key is unique to your account and should be kept secure. Do not share it publicly or commit it to version control.

## Make authenticated requests

Include your API key in the `Authorization` header using the bearer token format:

<CodeTabs syncKey="language">

```ts title="TypeScript"
const url = "https://dataservice.accuweather.com/currentconditions/v1/349727";

const response = await fetch(url, {
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Accept-Encoding": "gzip",
  },
});

const data: Record<string, unknown>[] = await response.json();
```

```python title="Python"
import requests

url = "https://dataservice.accuweather.com/currentconditions/v1/349727"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Accept-Encoding": "gzip",
}

response = requests.get(url, headers=headers)
data = response.json()
```

```csharp title="C#"
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY");
client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip");

var url = "https://dataservice.accuweather.com/currentconditions/v1/349727";
var response = await client.GetAsync(url);
var data = await response.Content.ReadAsStringAsync();
```

```java title="Java"
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://dataservice.accuweather.com/currentconditions/v1/349727"))
    .header("Authorization", "Bearer YOUR_API_KEY")
    .header("Accept-Encoding", "gzip")
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
String data = response.body();
```

```bash title="bash"
curl -H "Authorization: Bearer YOUR_API_KEY" \
     -H "Accept-Encoding: gzip,deflate" \
     "https://dataservice.accuweather.com/currentconditions/v1/349727"
```

</CodeTabs>

This example retrieves current weather conditions for New York City (location key 349727).

### Response format

Successful requests return JSON data with weather information. Unauthorized requests return a 401 status code.

```json
{
  "type": "https://httpproblems.com/http-status/401",
  "title": "Unauthorized",
  "status": 401,
  "instance": "/currentconditions/v1/349727",
  "trace": {
    "timestamp": "2025-07-26T08:00:13.887Z",
    "requestId": "f88dc27c-wmf1-4982-be8d-cc7b0f2a2b41",
    "buildId": "10a5efeb-jjf6-4971-89a5-51cfd7026e0f"
  },
  "Code": "Unauthorized",
  "Message": "API authorization failed",
  "Reference": "https://dataservice.accuweather.com/currentconditions/v1/349727"
}
```

## Authentication best practices

### Secure API keys

- Store API keys as environment variables.
- Never hardcode keys in client-side applications.
- Use server-side proxies for client applications.
- If you think your API key has been compromised, [contact AccuWeather support](/contact-us) immediately.

### Request headers

- Always include `Accept-Encoding: gzip,deflate` for compression.
- Use HTTPS endpoints exclusively. Unsecure HTTP is not supported.
- Include proper error handling for authentication failures.

## Troubleshoot

| Issue               | Solution                                                          |
| ------------------- | ----------------------------------------------------------------- |
| 401 Unauthorized    | Verify your API key is correct and active                         |
| 403 Forbidden       | Check your subscription limits in [Subscriptions](/subscriptions) |
| Rate limit exceeded | Implement caching and respect the `expires` header                |

## What next?

Now that you understand authentication, explore our APIs:

- [Core Weather quick-start](/documentation/core-weather-quick-start) - Get started with weather data.
- [MinuteCast™ quick-start](/documentation/minutecast-quick-start) - Minute-by-minute precipitation forecasts.
- [Best practices](/documentation/best-practices) - Optimize your API usage.
