> ## 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.

# Repo Tokens

> Manage and use tokens for accessing your Relace repos securely

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.

<Steps>
  <Step title="Creating a Repo Token">
    Start by creating a repo token that grants access to one or more of your Relace repos.

    ```typescript 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, // expire after 1 hour
    });

    const repoToken = result.token;
    console.log("Repo Token:", repoToken);
    ```

    Keep track of the generated token as it will not be shown again. You can use this token to access the specified repos.

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

  <Step title="Using Git Commands">
    When using [git commands](git-commands) to interact with your Relace repos, you can use the repo token in place of your API key in the clone URL:

    <CodeGroup>
      ```typescript Typescript SDK theme={null}
      import { Relace } from '@relace-ai/relace';

      const client = new Relace({ apiKey: 'YOUR_REPO_TOKEN' });

      // Specify the path to clone the repository in
      const repoPath = './repo_path';

      // Clone a repository by Repo ID
      await client.git(repoPath).clone({
          repoId: 'YOUR_REPO_ID',
          branch: 'main',
      });
      ```

      ```bash CLI theme={null}
      git clone -b main --depth 1 --quiet --single-branch https://token:YOUR_REPO_TOKEN@api.relace.run/v1/repo/YOUR_REPO_ID.git ./repo_path
      ```
    </CodeGroup>
  </Step>

  <Step title=" Using with Agents">
    When using a coding agent you can now use the repo token in place of your Relace API key:

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

    const client = new Relace({ apiKey: 'YOUR_REPO_TOKEN' });

    // Overwrite all repository content
    const result = await client.repo.update(repoId, {
      source: {
        type: 'files',
        files: [
          {
            filename: 'src/main.py',
            content:
              "def main():\n    print('Agent completely rewrote this')\n    return True",
          },
          {
            filename: 'README.md',
            content:
              '# Agent Updated Project\n\nThis project was updated by an AI agent.',
          },
        ],
      },
    });

    console.log(`Overwrote repository: ${JSON.stringify(result)}`);
    ```
  </Step>

  <Step title="Delete your Repo Tokens">
    You can delete repo tokens when they are no longer needed. For example, after a [sandboxed session](sandbox) is complete to ensure the token cannot be used again:

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

    const client = new Relace();

    const token = "rlcr-a1b2c3d4e5f67890abcdef1234567890abcdef12";
    await client.repoToken.delete(token);
    console.log("Repo token deleted successfully");
    ```
  </Step>
</Steps>
