The Gemini Notebook API uses [OAuth 2.0](https://developers.google.com/identity/protocols/oauth2.md.txt) 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](https://cloud.google.com/resource-manager/docs/creating-managing-projects).
- **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](https://notebook.google.com) 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`, `UploadSource`, `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](https://developers.google.com/identity/protocols/oauth2.md.txt) to create an
OAuth 2.0 client ID in your Google Cloud project:

1. **Enable the API** : In the [Google Cloud Console](https://console.cloud.google.com/apis/library/notebook.googleapis.com), 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](https://console.cloud.google.com/auth/branding) to configure your app details, and add the `https://www.googleapis.com/auth/notebook` scope on the [Data Access page](https://console.cloud.google.com/auth/scopes).
3. **Create an OAuth 2.0 client ID** : Go to the [Clients page](https://console.cloud.google.com/auth/clients), 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](https://developers.google.com/identity/protocols/oauth2.md.txt#scenarios) for your application type to obtain an access token and pass it in the `Authorization: Bearer` header:

### Python

```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

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

### JavaScript

```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](https://developers.google.com/identity/protocols/oauth2.md.txt).

## 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)](https://cloud.google.com/docs/authentication/application-default-credentials)
with the `gcloud` CLI.

> [!TIP]
> **Tip:** Want your AI coding assistant to handle Google Cloud project setup and local authentication for you? Copy the setup prompt from the [Quickstart](https://developers.google.com/notebook/docs/quickstart.md.txt#set-up-with-a-coding-agent) or [MCP guide](https://developers.google.com/notebook/docs/mcp.md.txt#agent-prompt).

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

```bash
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](https://cloud.google.com/docs/quotas/quota-project) for the
  request).

### REST

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

### Python

```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

```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());
```