- [HTTP request](https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.HTTP_TEMPLATE)
- [Path parameters](https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.PATH_PARAMETERS)
- [Request body](https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.request_body)
  - [JSON representation](https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.request_body.SCHEMA_REPRESENTATION)
- [Response body](https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.response_body)
  - [JSON representation](https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.AddContextFileResponse.SCHEMA_REPRESENTATION)
- [Authorization scopes](https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.aspect)
- [IAM Permissions](https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.aspect_1)

Uploads a context file to use as source for the assist calls within the session.

### HTTP request

Choose an endpoint:
global us   
`POST https://discoveryengine.googleapis.com/v1/{name=projects/*/locations/*/collections/*/engines/*/sessions/*}:addContextFile`

<br />

The URLs use [gRPC Transcoding](https://google.aip.dev/127) syntax.

### Path parameters

| Parameters ||
|---|---|
| `name` | `string` Required. The resource name of the Session. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}/sessions/{session}` If `-` is specified as the session ID, a new session is created with an automatically generated ID. |

### Request body

The request body contains data with the following structure:

| JSON representation |
|---|
| ``` { "fileName": string, "mimeType": string, // The following is a list of mutually exclusive fields. At most one of the // fields will be set in a response: "fileContents": string // End of mutually exclusive fields. } ``` |

| Fields ||
|---|---|
| `fileName` | `string` Required. The name of the file. |
| `mimeType` | `string` Optional. The content type of the file, see <https://www.iana.org/assignments/media-types/media-types.xhtml>. This field is required when the data source does not provide the content type. |
| The contents of the file. The following is a list of mutually exclusive fields. At most one of the fields will be set in a response: ||
| `fileContents` | `string (https://developers.google.com/discovery/v1/type-format format)` File contents provided inline. A base64-encoded string. |
| End of mutually exclusive fields. ||

### Response body

Response for the `https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#google.cloud.discoveryengine.v1.AssistantService.AddContextFile` method.

If successful, the response body contains data with the following structure:

| JSON representation |
|---|
| ``` { "session": string, "fileId": string, "tokenCount": string, "mimeType": string, "byteCount": string, "fileName": string } ``` |

| Fields ||
|---|---|
| `session` | `string` The name of the session, either the provided one, or the newly created one. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}/sessions/{session}` |
| `fileId` | `string` The ID of the uploaded file. |
| `tokenCount (deprecated)` | `string (https://developers.google.com/discovery/v1/type-format format)` > [!WARNING] > This item is deprecated! Deprecated: This field will not be set for all file types, and will eventually be removed. The length of the file measured in tokens. |
| `mimeType` | `string` Output only. The resolved content type of the uploaded file, see <https://www.iana.org/assignments/media-types/media-types.xhtml>. Unlike the optional, caller-supplied `https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.request_body.FIELDS.mime_type`, this is the content type the service actually resolved for the file. |
| `byteCount` | `string (https://developers.google.com/discovery/v1/type-format format)` Output only. The size of the uploaded file in bytes. |
| `fileName` | `string` Output only. The resolved name of the uploaded file, including its file extension. Unlike the caller-supplied `https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.request_body.FIELDS.file_name`, the service appends the extension that matches the resolved `https://docs.cloud.google.com/gemini/enterprise/docs/reference/rest/v1/projects.locations.collections.engines.sessions/addContextFile#body.AddContextFileResponse.FIELDS.mime_type` when the caller-supplied name has none, so usage audit logs capture the file type even for generically named AI-generated files. |

### Authorization scopes

Requires one of the following OAuth scopes:

- `https://www.googleapis.com/auth/cloud-platform`
- `https://www.googleapis.com/auth/discoveryengine.assist.readwrite`
- `https://www.googleapis.com/auth/discoveryengine.readwrite`
- `https://www.googleapis.com/auth/discoveryengine.serving.readwrite`

For more information, see the [Authentication Overview](https://docs.cloud.google.com/docs/authentication#authorization-gcp).

### IAM Permissions

Requires the following [IAM](https://cloud.google.com/iam/docs) permission on the `name` resource:

- `discoveryengine.sessions.addContextFile`

For more information, see the [IAM documentation](https://cloud.google.com/iam/docs).