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

# Create files

> Create files which can be passed as input to agents. This endpoint consumes a flat credit charge per upload. The response includes a `credits` field with the amount consumed, or `null` if the billing write fails — the upload still succeeds in that case.



## OpenAPI

````yaml post /files
openapi: 3.0.3
info:
  version: 0.1.1
  title: Datagrid API
  description: Datagrid API
servers:
  - url: https://api.datagrid.com/v1
security:
  - BearerAuth: []
paths:
  /files:
    post:
      tags:
        - Files
      summary: Create files
      description: >-
        Create files which can be passed as input to agents. This endpoint
        consumes a flat credit charge per upload. The response includes a
        `credits` field with the amount consumed, or `null` if the billing write
        fails — the upload still succeeds in that case.
      operationId: Files.createFiles
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
                  nullable: false
                expires_after:
                  type: integer
                  minimum: 1
                  maximum: 518400
                  nullable: true
                  description: >-
                    The number of seconds after creation when the file will
                    expire and be automatically deleted. Must be a positive
                    integer, maximum 6 days (518400s). If not provided, the file
                    will not expire.
      responses:
        '201':
          description: Successfully created file
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DatagridFile'
        '402':
          description: >-
            Credit limit exceeded. The organization does not have enough credits
            to perform this operation. Check your billing status and add credits
            to your account.
        '429':
          description: >-
            Rate limit exceeded. The request has been throttled because the rate
            limit for this endpoint has been reached. Check the `Retry-After`
            response header and retry after the specified number of seconds.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitError'
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import fs from 'fs';

            import Datagrid from 'datagrid-ai';


            const client = new Datagrid({
              apiKey: process.env['DATAGRID_API_KEY'], // This is the default and can be omitted
            });


            const fileObject = await client.files.create({ file:
            fs.createReadStream('path/to/file') });


            console.log(fileObject.id);
        - lang: Python
          source: |-
            import os
            from datagrid_ai import Datagrid

            client = Datagrid(
                api_key=os.environ.get("DATAGRID_API_KEY"),  # This is the default and can be omitted
            )
            file_object = client.files.create(
                file=b"Example data",
            )
            print(file_object.id)
components:
  schemas:
    DatagridFile:
      type: object
      description: >-
        The `File` object represents a document that has been uploaded to
        Datagrid.
      required:
        - object
        - id
        - filename
        - created_at
        - media_type
      properties:
        object:
          type: string
          enum:
            - file
          description: The object type, which is always `file`.
        id:
          type: string
          description: The file identifier, which can be referenced in the API endpoints.
        filename:
          type: string
          description: The name of the file
        created_at:
          type: string
          format: date-time
          description: The ISO string for when the file was created.
        media_type:
          type: string
          description: The media type of the file.
        expires_at:
          type: string
          format: date-time
          nullable: true
          description: >-
            The ISO timestamp when the file will expire and be automatically
            deleted, or null if the file does not expire.
        credits:
          nullable: true
          description: >-
            Credit consumption for this file upload. `null` when the billing
            lookup fails.
          allOf:
            - $ref: '#/components/schemas/OperationCredits'
    RateLimitError:
      type: object
      description: >-
        Returned when the rate limit is exceeded. Rate limits are enforced per
        teamspace, endpoint path, and HTTP method over a 60-second sliding
        window. Each endpoint may have its own limit — check the
        X-RateLimit-Limit response header for the effective value.
      required:
        - error
        - message
        - retryable
        - status_code
      properties:
        status_code:
          type: integer
          description: The HTTP status code (429).
        statusCode:
          type: integer
          deprecated: true
          description: Deprecated. Use status_code instead.
        error:
          type: string
          enum:
            - rate_limit_exceeded
          description: The error code identifying this as a rate limit error.
        message:
          type: string
          description: A human-readable error message.
        mitigation:
          type: string
          description: Suggested action to resolve the error.
        retryable:
          type: boolean
          description: Whether the request can be retried after a delay.
        details:
          type: object
          properties:
            reason:
              type: string
              description: A detailed explanation of why the rate limit was exceeded.
    OperationCredits:
      type: object
      required:
        - consumed
      properties:
        consumed:
          type: number
          description: The number of credits consumed by the operation.
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````