google / google/generative-ai-go

TLS Handshake Timeout and 400 Error Using Context Caching

Open
#244 0 comments 0 reactions 0 assignees View on GitHub
p2 status:triaged type:bug
Dominant language
Go
Stars
857
Forks
104
PR merge metrics
No merged PRs in 30d

Description

### 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:
```go
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.