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

> Create a new repo from files or a GitHub repo.

## Request Body

<ParamField body="source" type="object">
  Optional object to initialize the repo from existing source

  <Expandable title="properties" defaultOpen={false}>
    {' '}

    <ParamField body="type" type="string" required>
      The source type: `"files"` for direct file upload, `"git"` for GitHub repo, or `"relace"` for Relace repo
    </ParamField>

    {' '}

    <Tabs>
      <Tab title="From Files">
        <ParamField body="files" type="array" required>
          Array of file objects to include in the repo

          <Expandable title="properties" defaultOpen={false}>
            <ParamField body="filename" type="string" required>
              The path and filename for the file
            </ParamField>

            <ParamField body="content" type="string" required>
              The content of the file
            </ParamField>
          </Expandable>
        </ParamField>
      </Tab>

      <Tab title="From Git Repo">
        <ParamField body="url" type="string" required>
          Git repo URL to clone from
        </ParamField>

        <ParamField body="branch" type="string">
          Specific branch to clone
        </ParamField>

        <ParamField body="shallow" type="boolean" default={true}>
          Whether to import using a shallow clone

          <Warning>
            Commit history is not preserved when this option is enabled, so operations that require in-tact history (e.g. GitHub sync) will not work.
          </Warning>
        </ParamField>
      </Tab>

      <Tab title="From Relace Repo">
        <ParamField body="repo_id" type="string" required>
          Relace repo id to use as a template
        </ParamField>

        <ParamField body="copy_metadata" type="boolean">
          Optional flag to keep the metadata of the repo you are cloning
        </ParamField>

        <ParamField body="copy_remote" type="boolean">
          Optional flag to keep the orginal github remote if present
        </ParamField>
      </Tab>
    </Tabs>
  </Expandable>
</ParamField>

<ParamField body="metadata" type="object">
  Optional object containing any key-value pairs for custom metadata about the
  repo
</ParamField>

<ParamField body="auto_index" type="boolean" default={false}>
  Optional flag to enable automatic code indexing/embedding after repo creation and updates.

  <Warning>
    This parameter must be enabled for semantic retrieval to work.
  </Warning>
</ParamField>

## Response

<ResponseField name="repo_id" type="string">
  Unique identifier for the newly created repo
</ResponseField>

<ResponseField name="repo_head" type="string">
  Commit hash for the current repo head
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.relace.run/v1/repo \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
      -d '{
      "source": {
        "type": "files",
        "files": [
          {
            "filename": "src/search.ts",
            "content": "function findItem(array: Item[], targetId: string): Item | undefined {\n  for (let i = 0; i < array.length; i++) {\n    const item = array[i];\n    if (item.id === targetId) {\n      return item;\n    }\n  }\n  return undefined;\n}"
          },
          {
            "filename": "src/types.ts",
            "content": "interface Item {\n  id: string;\n  value: string;\n  metadata?: Record<string, unknown>;\n}"
          }
          # ... more files
        ]
      },
      "metadata": {
        "name": "my-codebase",
        "id": "my-internal-id"
      }
    }'
  ```

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

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

  const result = await client.repo.create({
      source: {
          type: "files",
          files: [
              {
                  filename: "src/search.ts",
                  content: "function findItem(array: Item[], targetId: string): Item | undefined {\n  for (let i = 0; i < array.length; i++) {\n    const item = array[i];\n    if (item.id === targetId) {\n      return item;\n    }\n  }\n  return undefined;\n}"
              },
              {
                  filename: "src/types.ts",
                  content: "interface Item {\n  id: string;\n  value: string;\n  metadata?: Record<string, unknown>;\n}"
              }
              // ... more files
          ]
      },
      metadata: {
          name: "my-codebase",
          id: "my-internal-id"
      }
  });

  console.log(result);
  ```

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

  client = Relace(api_key="YOUR_API_KEY")

  result = client.repo.create(
      source={
          "type": "files",
          "files": [
              {
                  "filename": "src/search.ts",
                  "content": (
                      "function findItem(array: Item[], targetId: string): Item | undefined {\n"
                      "  for (let i = 0; i < array.length; i++) {\n"
                      "    const item = array[i];\n"
                      "    if (item.id === targetId) {\n"
                      "      return item;\n"
                      "    }\n"
                      "  }\n"
                      "  return undefined;\n"
                      "}"
                  ),
              },
              {
                  "filename": "src/types.ts",
                  "content": (
                      "interface Item {\n"
                      "  id: string;\n"
                      "  value: string;\n"
                      "  metadata?: Record<string, unknown>;\n"
                      "}"
                  ),
              },
              # ... more files
          ],
      },
      metadata={
          "name": "my-codebase",
          "id": "my-internal-id",
      },
  )

  print(result)
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "repo_id": "123e4567-e89b-12d3-a456-426614174000",
    "repo_head": "a1b2c3d4e5f6789012345678901234567890abcdef"
  }
  ```
</ResponseExample>
