> ## AI Agent Context
> - Full documentation index: https://aistudio.google.com/llms.txt
> - Gemini Docs MCP server (consistent live info): https://gemini-api-docs-mcp.dev
> - Coding agent skills & setup guide: https://aistudio.google.com/docs/coding-agents.md

# Registering files

{% mark class="http-post" %}{% icon name="north_east" /%}`POST`{% /mark %} `https://generativelanguage.googleapis.com/v1beta/files:register`

Registers a Google Cloud Storage files with FileService. The user is
expected to provide Google Cloud Storage URIs and will receive a File
resource for each URI in return. Note that the files are not copied, just
registered with File API. If one file fails to register, the whole request
fails.

{% two-column-layout %}
  {% left-column %}
## Request Body  {% class="hide-from-toc" id="request-body" %}

  {% section class="api-ref-property-list" %}
  **uris**: {% mark %}required{% /mark %} `string array`

  The Google Cloud Storage URIs to register. Example: `gs://bucket/object`.

  {% /section %}

  {% /left-column %}

  {% right-column class="sticky" %}
  **Example request** {% class="example-heading" %}

  {% tabs %}
  {% tab label="REST" %}
  ```sh
  curl -X POST "https://generativelanguage.googleapis.com/v1beta/files:register" \
    -H "x-goog-api-key: $GEMINI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "uris": [
      "string"
    ]
  }'
  ```

  {% /tab %}

  {% /tabs %}

  {% /right-column %}

{% /two-column-layout %}

{% two-column-layout %}
  {% left-column %}
## Response  {% class="hide-from-toc" id="response" %}

  {% section class="api-ref-property-list" %}
  **files**: [`File`](/api-reference/files/register-files#Resource:File) `array`

  The registered files to be used when calling GenerateContent.

  {% /section %}

  {% /left-column %}

  {% right-column class="sticky" %}
  **Example response** {% class="example-heading" %}

  ```json
  {
    "files": [
      {
        "videoMetadata": {
          "videoDuration": "string"
        },
        "name": "string",
        "displayName": "string",
        "mimeType": "string",
        "sizeBytes": "string",
        "createTime": "string",
        "updateTime": "string",
        "expirationTime": "string",
        "sha256Hash": "string",
        "uri": "string",
        "downloadUri": "string",
        "state": "STATE_UNSPECIFIED",
        "source": "SOURCE_UNSPECIFIED",
        "error": {
          "code": 0,
          "message": "string",
          "details": [
            {}
          ]
        }
      }
    ]
  }
  ```

  {% /right-column %}

{% /two-column-layout %}

## Resources  {% class="hide-from-toc" id="resources" %}

### File  {% class="hide-from-toc" id="Resource:File" %}

A file uploaded to the API.

**Properties:**

{% section class="api-ref-property-list" %}
  {% details %}
  {% summary %}
  **metadata**: `Union type`

  Metadata for the File.

  {% /summary %}

  Union field `metadata` can be only one of the following:

  {% details %}
  {% summary %}
  **videoMetadata**: `VideoFileMetadata`

  Output only. Metadata for a video.

  {% /summary %}

  **videoDuration**: `string`

  Duration of the video.

  {% /details %}

  {% /details %}

  {% hr /%}

  **name**: `string`

  Immutable. Identifier. The [`File`](/api-reference/files/register-files#Resource:File) resource name. The ID (name excluding the "files/" prefix) can contain up to 40 characters that are lowercase alphanumeric or dashes (-). The ID cannot start or end with a dash. If the name is empty on create, a unique name will be generated. Example: `files/123-456`

  {% hr /%}

  **displayName**: `string`

  Optional. The human-readable display name for the [`File`](/api-reference/files/register-files#Resource:File). The display name must be no more than 512 characters in length, including spaces. Example: "Welcome Image"

  {% hr /%}

  **mimeType**: `string`

  Output only. MIME type of the file.

  {% hr /%}

  **sizeBytes**: `string`

  Output only. Size of the file in bytes.

  {% hr /%}

  **createTime**: `string`

  Output only. The timestamp of when the [`File`](/api-reference/files/register-files#Resource:File) was created.

  {% hr /%}

  **updateTime**: `string`

  Output only. The timestamp of when the [`File`](/api-reference/files/register-files#Resource:File) was last updated.

  {% hr /%}

  **expirationTime**: `string`

  Output only. The timestamp of when the [`File`](/api-reference/files/register-files#Resource:File) will be deleted. Only set if the [`File`](/api-reference/files/register-files#Resource:File) is scheduled to expire.

  {% hr /%}

  **sha256Hash**: `string`

  Output only. SHA-256 hash of the uploaded bytes.

  {% hr /%}

  **uri**: `string`

  Output only. The uri of the [`File`](/api-reference/files/register-files#Resource:File).

  {% hr /%}

  **downloadUri**: `string`

  Output only. The download uri of the [`File`](/api-reference/files/register-files#Resource:File).

  {% hr /%}

  {% details %}
  {% summary %}
  **state**: `string enum`

  Output only. Processing state of the File.

  {% /summary %}

  Possible values:

  - `STATE_UNSPECIFIED`: The default value. This value is used if the state is omitted.
  - `PROCESSING`: File is being processed and cannot be used for inference yet.
  - `ACTIVE`: File is processed and available for inference.
  - `FAILED`: File failed processing.

  {% /details %}

  {% hr /%}

  {% details %}
  {% summary %}
  **source**: `string enum`

  Source of the File.

  {% /summary %}

  Possible values:

  - `SOURCE_UNSPECIFIED`: Used if source is not specified.
  - `UPLOADED`: Indicates the file is uploaded by the user.
  - `GENERATED`: Indicates the file is generated by Google.
  - `REGISTERED`: Indicates the file is a registered, i.e. a Google Cloud Storage file.

  {% /details %}

  {% hr /%}

  **error**: [`Status`](/api-reference/files/register-files#Resource:Status)

  Output only. Error status if File processing failed.

{% /section %}

## Data Models  {% class="hide-from-toc" id="data-models" %}

### Status  {% class="hide-from-toc" id="Resource:Status" %}

The [`Status`](/api-reference/files/register-files#Resource:Status) type defines a logical error model that is suitable for
different programming environments, including REST APIs and RPC APIs. It is
used by [gRPC](https://github.com/grpc). Each [`Status`](/api-reference/files/register-files#Resource:Status) message contains
three pieces of data: error code, error message, and error details.

You can find out more about this error model and how to work with it in the
[API Design Guide](https://cloud.google.com/apis/design/errors).

**Properties:**

{% section class="api-ref-property-list" %}
  **code**: `integer`

  The status code, which should be an enum value of google.rpc.Code.

  {% hr /%}

  **message**: `string`

  A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the google.rpc.Status.details field, or localized by the client.

  {% hr /%}

  **details**: `object array`

  A list of messages that carry the error details. There is a common set of message types for APIs to use.

{% /section %}

