Authentication

The Gemini Notebook API uses OAuth 2.0 to authenticate requests on behalf of a Google user. Every request must include an OAuth 2.0 Bearer token in the Authorization HTTP header. The API doesn't accept API keys.

Before you begin

  • Create or select a Google Cloud project. You enable the API, configure the OAuth consent screen, and create OAuth clients in this project. To create a project, see Create a Google Cloud project.
  • Use a personal Google Account. During the Public Preview, the Gemini Notebook API is only available for personal Google Accounts. Requests authenticated with a Google Workspace account fail with 403 PERMISSION_DENIED (WORKSPACE_ACCOUNT_NOT_SUPPORTED).
  • Sign in to Gemini Notebook once. The API reads and writes the notebooks of the authorizing user, so each Google Account must have signed in to Gemini Notebook at least once before calling the API. If an account has never signed in to Gemini Notebook, CreateNotebook requests fail with 404 NOT_FOUND (Account not found for user.).

OAuth 2.0 scopes

Requests must be authenticated with an OAuth 2.0 token granted one of the following scopes:

Scope Access Supported methods
https://www.googleapis.com/auth/notebook Read and write access to notebooks and sources CreateNotebook, GetNotebook, ListNotebooks, UpdateNotebook, CreateSource, GetSource, ListSources
https://www.googleapis.com/auth/notebook.readonly Read-only access to notebooks and sources GetNotebook, ListNotebooks, GetSource, ListSources

Set up OAuth 2.0 for your application

To integrate the Gemini Notebook API into a web, desktop, or production application, follow the steps in Using OAuth 2.0 to Access Google APIs to create an OAuth 2.0 client ID in your Google Cloud project:

  1. Enable the API: In the Google Cloud Console, select your Google Cloud project and enable the Gemini Notebook API (notebook.googleapis.com).
  2. Configure the OAuth consent screen: Go to the Google Auth Platform branding page to configure your app details, and add the https://www.googleapis.com/auth/notebook scope on the Data Access page.
  3. Create an OAuth 2.0 client ID: Go to the Clients page, click Create client, and select your application type (for example, Desktop app or Web application). Download the client configuration JSON file as client_secret.json.
  4. Request an access token and call the API: Follow the OAuth 2.0 flow for your application type to obtain an access token and pass it in the Authorization: Bearer header:

Python

from google_auth_oauthlib.flow import InstalledAppFlow
import requests

SCOPES = ["https://www.googleapis.com/auth/notebook"]

flow = InstalledAppFlow.from_client_secrets_file("client_secret.json", SCOPES)
creds = flow.run_local_server(port=0)

resp = requests.get(
    "https://notebook.googleapis.com/v1/notebooks",
    headers={"Authorization": f"Bearer {creds.token}"},
)
print(resp.json())

REST

curl -s -X GET "https://notebook.googleapis.com/v1/notebooks" \
  -H "Authorization: Bearer $OAUTH_ACCESS_TOKEN"

JavaScript

const resp = await fetch("https://notebook.googleapis.com/v1/notebooks", {
  headers: {
    Authorization: `Bearer ${oauthAccessToken}`,
  },
});

console.log(await resp.json());

For details on OAuth 2.0 flows for web servers, installed apps, and client-side applications, see Using OAuth 2.0 to Access Google APIs.

Quickstart for local development with Application Default Credentials

If you want to try the REST API in your local development environment without creating an OAuth 2.0 client ID first, you can use Application Default Credentials (ADC) with the gcloud CLI.

1. Generate a local token with the gcloud CLI

Enable the API in your Google Cloud project and sign in with gcloud auth application-default login:

export PROJECT_ID="YOUR_PROJECT_ID"

# Enable the Gemini Notebook API in your Google Cloud project
gcloud services enable notebook.googleapis.com --project="$PROJECT_ID"

# Authenticate with Application Default Credentials and the Gemini Notebook API scope
gcloud auth application-default login \
  --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/notebook"

# Print an access token for local testing
export ACCESS_TOKEN=$(gcloud auth application-default print-access-token)

2. Make a request in your local environment

When calling the API with a token generated by gcloud auth application-default, pass two headers in your request:

  • Authorization: The Bearer token from gcloud auth application-default print-access-token.
  • x-goog-user-project: The ID of your Google Cloud project that has notebook.googleapis.com enabled (used as the quota project for the request).

REST

curl -s -X GET "https://notebook.googleapis.com/v1/notebooks" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "x-goog-user-project: $PROJECT_ID"

Python

import os
import requests

headers = {
    "Authorization": f"Bearer {os.environ['ACCESS_TOKEN']}",
    "x-goog-user-project": os.environ["PROJECT_ID"],
    "Content-Type": "application/json",
}

resp = requests.get("https://notebook.googleapis.com/v1/notebooks", headers=headers)
print(resp.json())

JavaScript

const resp = await fetch("https://notebook.googleapis.com/v1/notebooks", {
  headers: {
    Authorization: `Bearer ${process.env.ACCESS_TOKEN}`,
    "x-goog-user-project": process.env.PROJECT_ID,
    "Content-Type": "application/json",
  },
});

console.log(await resp.json());