> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Linking Cloudflare R2 as a source Canonical URL: https://posthog.com/docs/data-pipelines/sources/r2 > **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.posthog.com` instead of `https://app.posthog.com` (app host for links). ## On this page - [Step 1: Creating a bucket in R2](#step-1-creating-a-bucket-in-r2) - [Step 2: Create API tokens](#step-2-create-api-tokens) - [Step 3: Create the table in PostHog](#step-3-create-the-table-in-posthog) - [Step 4: Query the table](#step-4-query-the-table) ![](https://res.cloudinary.com/dmukukwp6/image/upload/texture_tan_9608fcca70) ![](https://res.cloudinary.com/dmukukwp6/image/upload/texture_tan_dark_a92b0e022d) Let AI connect your sources for you Skip the manual setup — run this in your project and the wizard auto-detects your databases and APIs and connects them to PostHog. `npx @posthog/wizard warehouse` ![PostHog Wizard hedgehog](https://res.cloudinary.com/dmukukwp6/image/upload/wizard_3f8bb7a240.png) ![](https://res.cloudinary.com/dmukukwp6/image/upload/wizard_3f8bb7a240.png)Let AI connect your sources for you The data warehouse can link to data in Cloudflare R2. To start, you'll need to: 1. Create a bucket in R2 2. Set up an access key and secret 3. Add data to the bucket 4. Create the table in PostHog ## Step 1: Creating a bucket in R2 1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/). 2. Go to the R2 overview and create a new bucket. We suggest using **Eastern North America** as a location hint if you're using PostHog Cloud US or **European Union** as a specific jurisdiction if you're using PostHog Cloud EU. 3. In your bucket, upload the data you want to query such as [CSV](https://posthog.com/tutorials/csv-query.md) or Parquet data. It can be as simple as a `.csv` file like this: ```csv id,name,email 1,John Doe,john@example.com 2,Jane Doe,jane@example.com ``` > **Adding data to R2 automatically:** See our [S3 docs](https://posthog.com/docs/data-warehouse/setup/s3.md#step-3-add-data-to-the-bucket) for how to set up Airbyte to automatically add data to the bucket. You can also use other ETL tools like Fivetran or Stitch. ## Step 2: Create API tokens 1. Head back to the R2 overview and under account details, click **Manage R2 API Tokens** 2. Click **Create API token**, give your token a name, choose **Object Read only** as the permission type, apply it to your bucket, and click **Create API Token** 3. Copy the credentials for S3 clients, including the **Access Key ID**, **Secret Access Key**, and jurisdiction-specific endpoint URL. These will not be shown again, so make sure to copy them to a safe place. ## Step 3: Create the table in PostHog 1. Go to the [Data pipeline page](https://app.posthog.com/data-management/sources) and the sources tab in PostHog 2. Click **New source** and under self managed, look for **Cloudflare R2** and click **Link** 3. Fill the table name, then use the data from Cloudflare: - For files URL pattern, use the jurisdiction-specific endpoint URL with your bucket name and file name like `https://b27247d543c.r2.cloudflarestorage.com/posthog-warehouse/cool_data.csv`. You can also use `*` to query multiple files. - Choose the correct file format - When using CSV format, you can configure **CSV quote handling** to control how quotes are processed: - **RFC 4180 double quotes** – for CSVs that use standard double-quote escaping (e.g., `"Hello ""World"""` becomes `Hello "World"`) - **Literal quotes** – for CSVs where quote characters are treated as literal values (default) - For access key, use your Access Key ID - For secret key, use your Secret Access Key 4. Click **Next** ## Step 4: Query the table Once it is done syncing, you can now [query](https://posthog.com/docs/data-warehouse/query.md) your new table using the table name.