Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A616567126 GPT WEB JAVA GoogleBardClient

From Leeroopedia
Knowledge Sources
Domains AI_Chat, External_API_Integration
Last Updated 2026-10-13 00:00 GMT

Overview

Concrete HTTP client for Google Bard AI that handles session authentication via SNlM0e token extraction and multi-turn conversation with session state tracking.

Description

The GoogleBardClient class implements the `AIClient` interface to communicate with Google Bard. On first `ask()`, it fetches the Bard homepage to extract the `SNlM0e` session token, then sends question requests using form-encoded POST with the session token. Conversation state (conversation ID, response ID, choice ID) is tracked for multi-turn conversations. The `reset()` method clears session state.

Usage

Create a `GoogleBardClient` with a Bard token (two cookie values separated by semicolon) and call `ask()` with questions. Call `reset()` between independent conversations.

Code Reference

Source Location

Signature

public class GoogleBardClient implements AIClient {
    private final String token;
    private final OkHttpClient httpClient;
    private final BardRequest bardRequest;

    public GoogleBardClient(String token);
    public GoogleBardClient(String token, Duration timeout);
    public GoogleBardClient(String token, OkHttpClient httpClient);

    @Override
    public Answer ask(String question);

    @Override
    public void reset();
}

Import

import com.intelligent.bot.service.bard.GoogleBardClient;

I/O Contract

Inputs

Name Type Required Description
token String Yes Two Bard cookie values (1PSID;1PSIDTS) separated by semicolon
question String Yes Question to ask Bard

Outputs

Name Type Description
ask returns Answer Contains answer text, images, and status

Usage Examples

Single Question

import com.intelligent.bot.service.bard.GoogleBardClient;

GoogleBardClient client = new GoogleBardClient("cookie1PSID;cookie1PSIDTS");
Answer answer = client.ask("What is the weather today?");
System.out.println(answer.getChosenAnswer());

Multi-turn Conversation

// First question
Answer a1 = client.ask("Tell me about Java");
// Follow-up (uses conversation state)
Answer a2 = client.ask("Show me an example");
// Reset for new conversation
client.reset();
Answer a3 = client.ask("Different topic entirely");

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment