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

# Download a file

> Download a file that a flow or a grid produced, from the URL its response gave.



## OpenAPI

````yaml api-reference/openapi.yaml GET /v1/files/download
openapi: 3.0.3
info:
  title: QX API
  version: '1.0'
  description: >-
    Run what you build in QX from your own code. Message agents, execute flows
    and grids, and read their results.
servers:
  - url: https://api.qxlabs.com
security:
  - bearerAuth: []
tags:
  - name: Agents
    description: >-
      Message agents through OpenAI's Responses API, so OpenAI's SDKs work with
      a QX API key.
  - name: Flows
    description: Execute flows and follow their executions.
  - name: Grids
    description: Execute grids, follow their executions and read their rows.
  - name: Files
    description: Download the files that flows and grids produce.
paths:
  /v1/files/download:
    get:
      tags:
        - Files
      summary: Download a file
      description: >
        Downloads a file that a flow or a grid produced.

        A flow execution's node outputs and a sheet's cells return a file as a
        file object: its `name`, `content_type`, `size` in bytes and a `url`.
        Request that `url` with your API key to get the file.

        You can only download files that belong to your org, and your key needs
        access to flow executions or to sheet rows.
      operationId: downloadFile
      parameters:
        - name: key
          in: query
          required: true
          schema:
            type: string
          description: >-
            Identifies the file. It is already part of the `url` in a file
            object, so use that URL as it is
          example: >-
            5f2b8c1d9e3a4b7c8d6e0f1a2b3c4d5e/files/0c9e2f7a41b84d3e9a6f5b1c8d2e7f30/big-orders.csv
      responses:
        '200':
          description: The file, with `Content-Disposition` carrying its name
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        '400':
          description: '`key` is missing'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: key is required
        '403':
          description: Your key has access to neither flow executions nor sheet rows
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: There's no such file, or it belongs to another org
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: Read rate limit exceeded for flows endpoints
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >
            curl -L
            "https://api.qxlabs.com/v1/files/download?key=5f2b8c1d9e3a4b7c8d6e0f1a2b3c4d5e%2Ffiles%2F0c9e2f7a41b84d3e9a6f5b1c8d2e7f30%2Fbig-orders.csv"
            \
              -H "Authorization: Bearer <YOUR_QX_API_KEY>" \
              -o big-orders.csv
        - lang: python
          label: Python
          source: |
            import requests

            headers = {"Authorization": "Bearer <YOUR_QX_API_KEY>"}

            execution = requests.get(
                "https://api.qxlabs.com/v1/flows/c71a5f0e1d2b4a7e9a513f6f0d2b8e10/executions/9b2e4d713a5c4f8bb6e21c7d9a0f3e58",
                headers=headers,
            ).json()

            # Save every file the flow's nodes output
            for node in execution["nodes"]:
                for value in node["output"].values():
                    if isinstance(value, dict) and value.get("type") == "file":
                        content = requests.get(value["url"], headers=headers).content
                        with open(value["name"], "wb") as f:
                            f.write(content)
        - lang: typescript
          label: TypeScript
          source: |
            import { writeFile } from "node:fs/promises";

            const headers = { Authorization: "Bearer <YOUR_QX_API_KEY>" };

            const execution = await (
              await fetch(
                "https://api.qxlabs.com/v1/flows/c71a5f0e1d2b4a7e9a513f6f0d2b8e10/executions/9b2e4d713a5c4f8bb6e21c7d9a0f3e58",
                { headers },
              )
            ).json();

            // Save every file the flow's nodes output
            for (const node of execution.nodes) {
              for (const value of Object.values<any>(node.output)) {
                if (value?.type === "file") {
                  const file = await fetch(value.url, { headers });
                  await writeFile(value.name, Buffer.from(await file.arrayBuffer()));
                }
              }
            }
components:
  schemas:
    Error:
      type: object
      properties:
        error:
          type: string
          description: What went wrong
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Your QX API key. The `X-API-Key` header works too

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.