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

# Create Repo Token

> Create a scoped API token for specific repositories

Repo tokens provide scoped read/write access to specific repositories. They can be used in place of your Relace API key for repo-specific operations.

<Note>Repo tokens are strongly recommended for use in sandboxed environments to prevent unintended access to other resources associated with your Relace account.</Note>

## Request Body

<ParamField body="name" type="string" required>
  A descriptive name for the token
</ParamField>

<ParamField body="repo_ids" type="array" required>
  Array of repository UUIDs that this token will have read/write access to
</ParamField>

<ParamField body="ttl_seconds" type="integer" optional>
  Optional time-to-live in seconds for the token. If set, the token will expire after this duration.
</ParamField>

## Response

<ResponseField name="token" type="string">
  The generated repo token value.

  <Warning>Tokens can only be referenced by this value; make sure to store it for future use.</Warning>
</ResponseField>

<ResponseField name="name" type="string">
  The name of the repo token
</ResponseField>

<ResponseField name="repo_ids" type="array">
  Array of repository UUIDs this token has read/write access to
</ResponseField>

<ResponseField name="expires_at" type="string" optional>
  The ISO 8601 timestamp when this token will expire, if a TTL was set
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.relace.run/v1/repo_token \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "my-token",
      "repo_ids": [
        "123e4567-e89b-12d3-a456-426614174000",
        "987fcdeb-51a2-43f7-b123-456789abcdef"
      ],
      "ttl_seconds": 3600
    }'
  ```

  ```typescript TypeScript SDK theme={null}
  import { Relace } from "@relace-ai/relace";

  const client = new Relace({ apiKey: "YOUR_API_KEY" });

  const result = await client.repoToken.create({
      name: "my-token",
      repo_ids: [
          "123e4567-e89b-12d3-a456-426614174000",
          "987fcdeb-51a2-43f7-b123-456789abcdef"
      ],
      ttl_seconds: 3600,
  });

  console.log(result);
  ```

  ```python Python SDK theme={null}
  from relace import Relace

  client = Relace(api_key="YOUR_API_KEY")

  result = client.repo_token.create(
      name="my-token",
      repo_ids=[
          "123e4567-e89b-12d3-a456-426614174000",
          "987fcdeb-51a2-43f7-b123-456789abcdef",
      ],
      ttl_seconds=3600,
  )

  print(result)
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "name": "my-token",
    "token": "rlcr-a1b2c3d4e5f67890abcdef1234567890abcdef12",
    "repo_ids": [
      "123e4567-e89b-12d3-a456-426614174000",
      "987fcdeb-51a2-43f7-b123-456789abcdef"
    ],
    "expires_at": "2025-12-01T12:00:00Z"
  }
  ```
</ResponseExample>

## Using Repo Tokens

Once created, repo tokens can be used as bearer tokens for authentication on any `/repo/{repo_id}` endpoint that they are scoped for:

```bash Example Usage theme={null}
# Use the repo token to search within an authorized repo
curl -X POST https://api.relace.run/v1/repo/123e4567-e89b-12d3-a456-426614174000/search \
  -H "Authorization: Bearer rlcr-a1b2c3d4e5f67890abcdef1234567890abcdef12" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "authentication logic"
  }'
```
