> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wappfy.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> API keys या JWT tokens का उपयोग करके Wappfy API के साथ authenticate कैसे करें।

# Authentication

Wappfy API दो authentication methods को support करता है। सभी requests में इनमें से एक शामिल होना चाहिए।

## API Key (अनुशंसित)

अपनी API key `X-Api-Key` header में pass करें:

```bash theme={null}
curl https://api.wappfy.io/api/instances \
  -H "X-Api-Key: wappfy_sk_abc123def456..."
```

### API key बनाना

API keys dashboard या API के माध्यम से बनाई जाती हैं। Keys एक user से जुड़ी होती हैं और user के account के समान permissions रखती हैं।

```bash theme={null}
curl -X POST https://api.wappfy.io/api/api-keys \
  -H "Authorization: Bearer YOUR_SUPABASE_JWT" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Production Key" }'
```

<Warning>
  Key value केवल creation के समय एक बार लौटाया जाता है। इसे सुरक्षित रूप से store करें।
</Warning>

## Bearer Token (Supabase JWT)

Supabase access token को `Authorization` header में pass करें:

```bash theme={null}
curl https://api.wappfy.io/api/instances \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
```

JWT tokens short-lived होते हैं और उन्हें refresh करना पड़ता है। ये आमतौर पर frontend dashboard द्वारा उपयोग किए जाते हैं, server-to-server integrations के लिए नहीं।

## सुरक्षा सर्वोत्तम प्रथाएं

<AccordionGroup>
  <Accordion title="Server-to-server के लिए API keys उपयोग करें">
    API keys expire नहीं होती हैं और backend integrations के लिए manage करना आसान है।
  </Accordion>

  <Accordion title="Keys को नियमित रूप से rotate करें">
    यदि कोई key compromise हो जाए, तो उसे delete करें और नई बनाएं।
  </Accordion>

  <Accordion title="हमेशा HTTPS उपयोग करें">
    सभी API requests को HTTPS उपयोग करना अनिवार्य है। HTTP requests reject कर दी जाएंगी।
  </Accordion>

  <Accordion title="Frontend code में keys expose न करें">
    API keys केवल server-side code में उपयोग की जानी चाहिए, कभी भी client-side JavaScript में नहीं।
  </Accordion>
</AccordionGroup>

## Error responses

| Status | विवरण                                    |
| ------ | ---------------------------------------- |
| `401`  | Authentication token गायब या अमान्य है   |
| `403`  | इस resource के लिए अपर्याप्त permissions |
