Skip to content

TLS Handshake Timeout and 400 Error Using Context Caching #244

Description

@AlvaroG13191704

Description of the bug:

I'm encountering intermittent errors when using context caching with the gemini-1.5-pro-002 model or another in the generative-ai-go library. The errors include TLS handshake timeouts and API error 400 responses.

Here are some examples of the errors I encountered:

Image

Code to Reproduce

Here is the relevant part of my implementation:

ctx := context.Background()
argcc := &genai.CachedContent{
    Expiration: genai.ExpireTimeOrTTL{
        ExpireTime: time.Now().Add(1 * time.Hour),
    },
    Model:             "gemini-1.5-pro-002",
    SystemInstruction: genai.NewUserContent(genai.Text("Example system instruction")),
    Contents:          content,  // Multiple PDFs loaded as genai.Content
}

cc, err := g.Client.CreateCachedContent(ctx, argcc)
if err != nil {
    fmt.Printf("Error creating cached content: %v", err)
    panic(err)
}

resp, err := g.Session.SendMessage(ctx, genai.Text("Example prompt"))
if err != nil {
    fmt.Printf("Error sending message: %v", err)
    panic(err)
}

Actual vs expected behavior:

I should receive the response

Any other information you'd like to share?

I'm using the latest version of the SDK.

I've already set my json credentials and Gemini API KEY.

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2status:triagedIssue/PR triaged to the corresponding sub-teamtype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions