title: How to use session tokens correctly?
body: <p>I am using the Java client for the Google Places API:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dependency&gt;
      &lt;groupId&gt;com.google.maps&lt;/groupId&gt;
      &lt;artifactId&gt;google-maps-services&lt;/artifactId&gt;
      &lt;version&gt;0.9.1&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>The following is how I use the autocomplete API on my server:</p>
  
  <pre class="lang-java prettyprint-override"><code>public List&lt;AutocompletePrediction&gt; searchAddress(String query) {
  
      List&lt;AutocompletePrediction&gt; predictions = new ArrayList&lt;&gt;();
  
      try {
          AutocompletePrediction[] autocompletePredictions = PlacesApi
                  .placeAutocomplete(geoApiContext, query, null) 
  
          predictions.addAll(Arrays.asList(autocompletePredictions));
      } catch (ApiException | InterruptedException | IOException e) {
          e.printStackTrace();
      }
  
      return predictions;
  }
  </code></pre>
  
  <p>Now, at the time I am passing <code>null</code> as the <code>sessionToken</code>:</p>
  
  <pre><code>.placeAutocomplete(geoApiContext, query, null) 
  </code></pre>
  
  <p>mainly because I am not entirely sure how these are supposed to work.</p>
  
  <p>I could create <em>one</em> token every 2 minutes and use that token no matter which user is currently typing.</p>
  
  <p>So this would mean if two users search for "location" and "place", the incoming queries might look like this:</p>
  
  <pre><code>[User 1] 1. lo
  [User 2] 2. p
  [User 1] 3. loca
  [User 2] 4. plac
  [User 1] 5. locat
  [User 1] 6. location
  [User 2] 7. place
  </code></pre>
  
  <p>now, I could use for all those requests the same token <code>X</code> and create a new one every one or two minutes but I don't know whether this is allowed and whether this affects billing.</p>
  
  <p>The other way would be to create a cache per user which stores for user <code>1</code> and <code>2</code> a token <code>X1</code> and <code>X2</code> respectively. This solution would be a little more complex which is why I'd like to know whether the first solution would already work in the sense of I won't get billed for every single request.</p>
  
  <h3>Documentation</h3>
  
  <ul>
  <li><a href="https://developers.google.com/places/web-service/session-tokens" rel="nofollow noreferrer">Session Tokens</a></li>
  <li><a href="https://developers.google.com/places/web-service/usage-and-billing#about-autocomplete-sessions" rel="nofollow noreferrer">Autocomplete Sesssions</a></li>
  </ul>