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

# Authentication

GraphQL API Authentication

## Overview

All GraphQL API requests to pyck must be authenticated. This document explains how to authenticate your API requests.

## Authentication Methods

The pyck GraphQL API supports two primary authentication methods:

### 1. JWT Token Authentication

JWT (JSON Web Token) authentication is the most common method and involves including a valid JWT token in the Authorization header of your requests.

```
Authorization: Bearer <your_jwt_token>
```

JWT tokens are typically obtained through the ZITADEL authentication flow. Once you have a token, include it in all your API requests.

### 2. Personal Access Token (PAT)

For system integrations and automation, you can use a Personal Access Token:

```
Authorization: Bearer <your_personal_access_token>
```

PATs are long-lived tokens that can be created through the pyck administration interface.

## Example Authentication Flow

### 1. Obtain a JWT Token

Authenticate with ZITADEL to obtain a JWT token. This typically involves redirecting the user to the ZITADEL login page and handling the callback with the token.

### 2. Make Authenticated Requests

Once you have a token, include it in your GraphQL requests:

```javascript
// Example with fetch API
const response = await fetch('https://api.pyck.ai/graphql', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${token}`
  },
  body: JSON.stringify({
    query: `
      query {
        me {
          id
          name
          email
        }
      }
    `
  })
});
```

### 3. Handle Token Expiration

JWT tokens expire after a certain period. When a token expires, you'll receive a 401 Unauthorized response. You should:

1. Detect the 401 response
2. Request a new token using the refresh token flow
3. Retry the original request with the new token

## Testing Authentication

You can test your authentication by querying the `me` endpoint, which returns information about the authenticated user:

```graphql
query {
  me {
    id
    name
    email
  }
}
```

If authentication is successful, you'll receive information about your user. If not, you'll receive an error message.


---

# 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.pyck.cloud/graphql-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.
