Class GenerateContentResponse

Response message for PredictionService.GenerateContent.

Constructors

Properties

candidates?: Candidate[]

Response variations returned by the model.

createTime?: string

Timestamp when the request is made to the server.

modelVersion?: string

Output only. The model version used to generate the response.

Output only. Content filter results for a prompt sent in the request. Note: Sent only in the first stream chunk. Only happens when no candidates were generated due to content violations.

responseId?: string

Identifier for each response.

Usage metadata about the response(s).

Accessors

  • get codeExecutionResult(): undefined | string

    Returns the first code execution result from the first candidate in the response.

    Returns undefined | string

    If there are multiple candidates in the response, the code execution result from the first one will be returned. If there are no code execution result in the response, undefined will be returned.

    const response = await ai.models.generateContent({
    model: 'gemini-2.0-flash',
    contents:
    'What is the sum of the first 50 prime numbers? Generate and run code for the calculation, and make sure you get all 50.'
    config: {
    tools: [{codeExecution: {}}],
    },
    });

    console.debug(response.codeExecutionResult);
  • get executableCode(): undefined | string

    Returns the first executable code from the first candidate in the response.

    Returns undefined | string

    If there are multiple candidates in the response, the executable code from the first one will be returned. If there are no executable code in the response, undefined will be returned.

    const response = await ai.models.generateContent({
    model: 'gemini-2.0-flash',
    contents:
    'What is the sum of the first 50 prime numbers? Generate and run code for the calculation, and make sure you get all 50.'
    config: {
    tools: [{codeExecution: {}}],
    },
    });

    console.debug(response.executableCode);
  • get functionCalls(): undefined | FunctionCall[]

    Returns the function calls from the first candidate in the response.

    Returns undefined | FunctionCall[]

    If there are multiple candidates in the response, the function calls from the first one will be returned. If there are no function calls in the response, undefined will be returned.

    const controlLightFunctionDeclaration: FunctionDeclaration = {
    name: 'controlLight',
    parameters: {
    type: Type.OBJECT,
    description: 'Set the brightness and color temperature of a room light.',
    properties: {
    brightness: {
    type: Type.NUMBER,
    description:
    'Light level from 0 to 100. Zero is off and 100 is full brightness.',
    },
    colorTemperature: {
    type: Type.STRING,
    description:
    'Color temperature of the light fixture which can be `daylight`, `cool` or `warm`.',
    },
    },
    required: ['brightness', 'colorTemperature'],
    };
    const response = await ai.models.generateContent({
    model: 'gemini-2.0-flash',
    contents: 'Dim the lights so the room feels cozy and warm.',
    config: {
    tools: [{functionDeclarations: [controlLightFunctionDeclaration]}],
    toolConfig: {
    functionCallingConfig: {
    mode: FunctionCallingConfigMode.ANY,
    allowedFunctionNames: ['controlLight'],
    },
    },
    },
    });
    console.debug(JSON.stringify(response.functionCalls));
  • get text(): undefined | string

    Returns the concatenation of all text parts from the first candidate in the response.

    Returns undefined | string

    If there are multiple candidates in the response, the text from the first one will be returned. If there are non-text parts in the response, the concatenation of all text parts will be returned, and a warning will be logged. If there are thought parts in the response, the concatenation of all text parts excluding the thought parts will be returned.

    const response = await ai.models.generateContent({
    model: 'gemini-2.0-flash',
    contents:
    'Why is the sky blue?',
    });

    console.debug(response.text);
MMNEPVFCICPMFPCPTTAAATR