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

# Upload File

> Upload a file to the repository

## Path Parameters

<ParamField path="repo_id" type="string" required>
  Repo ID
</ParamField>

<ParamField path="file_path" type="string" required>
  Path to the file within the repository (URL encoded)
</ParamField>

## Request Body

The request body should contain the raw file content as binary data. Set the `Content-Type` header to `application/octet-stream`.

## Response

Returns HTTP status `201 Created` on success.

<ResponseField name="repo_id" type="string">
  The repository ID that was updated
</ResponseField>

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

<ResponseField name="changed_files" type="array">
  Array of file paths that were modified
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X PUT https://api.relace.run/v1/repo/3fa85f64-5717-4562-b3fc-2c963f66afa6/file/src/main.py \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/octet-stream" \
    --data-binary "def main():
      print('Hello World!')

  if __name__ == '__main__':
      main()"
  ```

  ```typescript TypeScript theme={null}
  const repoId = "3fa85f64-5717-4562-b3fc-2c963f66afa6";
  const filePath = "src/main.py";
  const content = `def main():
      print("Hello World!")

  if __name__ == "__main__":
      main()`;

  const url = `https://api.relace.run/v1/repo/${repoId}/file/${encodeURIComponent(filePath)}`;
  const headers = {
      "Authorization": "Bearer YOUR_API_KEY",
      "Content-Type": "application/octet-stream"
  };

  const response = await fetch(url, {
      method: "PUT",
      headers: headers,
      body: content
  });
  const data = await response.json();
  console.log(data);
  ```

  ```javascript JavaScript theme={null}
  const repoId = '3fa85f64-5717-4562-b3fc-2c963f66afa6';
  const filePath = 'src/main.py';
  const content = `def main():
      print("Hello World!")

  if __name__ == "__main__":
      main()`;

  const url = `https://api.relace.run/v1/repo/${repoId}/file/${encodeURIComponent(
    filePath
  )}`;

  fetch(url, {
    method: 'PUT',
    headers: {
      Authorization: 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/octet-stream',
    },
    body: content,
  })
    .then((response) => response.json())
    .then((data) => console.log(data));
  ```

  ```javascript Next.js Example theme={null}
  // Example from a Next.js API route
  const file = { name: 'src/main.py', content: 'base64-encoded-content' };
  const buffer = Buffer.from(file.content, 'base64');

  const uploadRes = await fetch(
    `${
      process.env.NEXT_PUBLIC_AGENT_URL
    }/repo/${repoId}/file/${encodeURIComponent(file.name)}`,
    {
      method: 'PUT',
      headers: {
        Authorization: `Bearer ${process.env.RELACE_API_KEY}`,
        'Content-Type': 'application/octet-stream',
      },
      body: buffer,
    }
  );

  if (!uploadRes.ok) {
    throw new Error(`Failed to upload file: ${file.name}`);
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "repo_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "repo_head": "abc123def456789",
    "changed_files": ["src/main.py"]
  }
  ```
</ResponseExample>
