Method: projects.locations.collections.engines.sessions.addContextFile

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

HTTP request

POST https://discoveryengine.googleapis.com/v1beta/{name=projects/*/locations/*/collections/*/engines/*/sessions/*}:addContextFile

The URL uses gRPC Transcoding 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,

  // Union field file can be only one of the following:
  "fileContents": string
  // End of list of possible types for union field file.
}
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.

Union field file. The contents of the file. file can be only one of the following:
fileContents

string (bytes format)

File contents provided inline.

A base64-encoded string.

Response body

Response for the 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 (int64 format)

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 AddContextFileRequest.mime_type, this is the content type the service actually resolved for the file.

byteCount

string (int64 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 AddContextFileRequest.file_name, the service appends the extension that matches the resolved mimeType 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.

IAM Permissions

Requires the following IAM permission on the name resource:

  • discoveryengine.sessions.addContextFile

For more information, see the IAM documentation.