Using a single API key for multiple sessions

I want to create a chat app with multiple sessions and have some questions about the API.

  1. Can I create a chat app with multiple sessions with one Gemini API? Or do I need an API for each session?
  2. Do I need to pass the session ID to the API? (I didn’t think I could pass it in the documentation)
  3. If I have multiple sessions with one Gemini API, is it correct that the request limit is calculated based on the total value of each session?

Welcome to the Forums!

You’re asking some good questions, but we may need to untangle them a little bit to understand what is going on from the Gemini API perspective.

Your title refers to an API key, so I assume that’s what you mean by this questions. You may need to clarify if this isn’t what you meant.

But to answer - yes, you can use the same API Key for each session. In fact, this is what you’re expected to do. Have a Key for each application.

No. As you note - there is no place to pass a session ID.

The Gemini API does not maintain any session information itself. This is known as working in a “stateless” way - the Gemini API server doesn’t maintain any information (or state) about the conversation.

You must pass the entire conversation every time you send a message to the Gemini API.

It is up to you to manage those sessions and make sure that the right person talks to the right session. That the right conversation is attached to that session. Etc.

Since the Gemini API doesn’t care about a session, the quotas are all based on what you send it every time. This means that the entire history, if you send it, is counted each time you send it.

1 Like

Thank you very much!
The information given is very useful and allows us to accelerate the development of our app!

1 Like