aboutsummaryrefslogtreecommitdiff
path: root/apps/docs/deployment/self-hosting.mdx
blob: 7f7db4d31bdcb5f96f0fee36e46b036a02bbfb5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
---
title: 'Self Hosting'
description: 'Deploy your own instance of the supermemory API on Cloudflare Workers'
---

<Warning>
This guide is intended for **enterprise customers only** who have specifically opted for self-hosting as part of their enterprise plan. If you're on a standard plan, please use our hosted API at [console.supermemory.ai](https://console.supermemory.ai).
</Warning>

## Prerequisites

Before you start, you'll need to gather several API keys and set up accounts with various services. This comprehensive guide will walk you through obtaining each required component.

### Enterprise Deployment Package

Your enterprise deployment package is provided by the supermemory team and contains:
- Your unique Host ID (`NEXT_PUBLIC_HOST_ID`)
- The compiled JavaScript bundle
- The deployment script

Contact your supermemory enterprise representative to receive your deployment package.

### Cloudflare


#### Create Account

1. Go to [cloudflare.com](https://dash.cloudflare.com/sign-up) and create an account
3. Your **Account ID** is the long randon string in the URL bar

#### Create API Token

1. Navigate to [Cloudflare API Tokens](https://dash.cloudflare.com/?to=/:account/api-tokens)
2. Click **"Create Token"**
3. Use the **"Custom token"** template
4. Configure the token with these permissions:
   - **Account:AI Gateway:Edit**
   - **Account:Hyperdrive:Edit**
   - **Account:Workers KV Storage:Edit**
   - **Account:Workers R2 Storage:Edit**
7. Click **"Continue to summary"** → **"Create Token"**
8. **Important**: Copy and securely store the token immediately (it won't be shown again)

#### Enable Workers

1. In your Cloudflare dashboard, go to **Workers & Pages**
2. If prompted, accept the Workers terms of service
3. Choose a subdomain for your workers (e.g., `yourcompany.workers.dev`)

Your `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` are now ready.

### Database

You'll need to provide a PostgreSQL connection string via the `DATABASE_URL` environment variable.

The database must:
- Support the **pgvector extension** for vector operations
- Be accessible from Cloudflare Workers
- Support SSL connections
- Allow connections from Cloudflare's IP ranges

Your connection string should follow this format:
```
postgresql://username:password@hostname:port/database
```

### LLM Providers

#### OpenAI

1. Go to [platform.openai.com](https://platform.openai.com)
2. Sign in or create an account
3. Navigate to **API Keys** in the left sidebar
4. Click **"Create new secret key"**
5. Name your key (e.g., "supermemory Self-Hosted")
6. Copy the key and store it securely
7. Add billing information if you haven't already

#### Anthropic

1. Go to [console.anthropic.com](https://console.anthropic.com)
2. Create an account and complete verification
3. Navigate to **API Keys**
4. Click **"Create Key"**
5. Name your key and copy it securely

#### Gemini

1. Go to [Google AI Studio](https://aistudio.google.com)
2. Sign in with your Google account
3. Click **"Get API key"** → **"Create API key"**
4. Choose an existing Google Cloud project or create a new one
5. Copy your API key

#### Groq

1. Go to [console.groq.com](https://console.groq.com)
2. Sign up for an account
3. Navigate to **API Keys**
4. Click **"Create API Key"**
5. Name your key and copy it



{/* TODO: Add OAuth documentation */}
{/* ### Authentication Providers
#### GitHub OAuth (Optional)

1. Go to [GitHub Developer Settings](https://github.com/settings/developers)
2. Click **"New OAuth App"**
3. Fill in the application details:
   - **Application name**: Your app name
   - **Homepage URL**: Your API domain (e.g., `https://api.yourdomain.com`)
   - **Authorization callback URL**: `https://api.yourdomain.com/api/auth/callback/github`
4. Click **"Register application"**
5. Note the **Client ID** and generate a **Client Secret**
6. Use these for `AUTH_GITHUB_ID` and `AUTH_GITHUB_SECRET`

#### Google OAuth (Optional)

1. Go to [Google Cloud Console](https://console.cloud.google.com)
2. Create a new project or select an existing one
3. Enable the **Google+ API**
4. Go to **Credentials** → **Create Credentials** → **OAuth client ID**
5. Choose **Web application**
6. Add your domain to **Authorized JavaScript origins**
7. Add `https://api.yourdomain.com/api/auth/callback/google` to **Authorized redirect URIs**
8. Copy the **Client ID** and **Client secret**
9. Use these for `AUTH_GOOGLE_ID` and `AUTH_GOOGLE_SECRET` */}

### Email Service Setup

#### Resend

1. Go to [resend.com](https://resend.com) and create an account
2. Navigate to **API Keys**
3. Click **"Create API Key"**
4. Name your key (e.g., "supermemory Production")
5. Copy the key for `RESEND_API_KEY`
6. Verify your sending domain in the **Domains** section

### Connectors (Optional)

#### Google Drive

1. Go to [Google Cloud Console](https://console.cloud.google.com)
2. Create or select a project
3. Enable the **Google Drive API**
4. Go to **Credentials** → **Create Credentials** → **OAuth client ID**
5. Configure the OAuth consent screen if required
6. Choose **Web application**
7. Add authorized redirect URIs for your domain
8. Copy `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET`

#### Microsoft OneDrive

1. Go to [Azure Portal](https://portal.azure.com)
2. Navigate to **Microsoft Entra ID** → **App registrations**
3. Click **"New registration"**
4. Name your app and set redirect URI
5. Go to **Certificates & secrets** → **New client secret**
6. Copy the **Application (client) ID** and **Client secret**
7. Use for `MICROSOFT_CLIENT_ID` and `MICROSOFT_CLIENT_SECRET`

#### Notion

1. Go to [Notion Developers](https://developers.notion.com)
2. Click **"Create new integration"**
3. Fill in the integration details
4. Copy the **Internal Integration Token**
5. Set up OAuth if needed for user connections
6. Use for `NOTION_CLIENT_ID` and `NOTION_CLIENT_SECRET`

---

## Setup deployment files

Extract the deployment package provided by the supermemory team to your preferred directory:

```bash
# Extract the deployment package
$ unzip supermemory-enterprise-deployment.zip
$ cd supermemory-deployment
```

---

## Configure environment variables

The deployment script reads **all** environment variables from your shell at runtime. We ship an example file that lists the full set supported by the worker.

```bash
# Copy the template and start editing
$ cp packages/alchemy/env.example .env

# Open the file in your editor of choice and fill in the blanks
$ $EDITOR .env
```

Below is a quick reference.  
**Required** values are mandatory for a successful deploy – leave optional ones empty if you don't need the related feature.

| Name | Required? | Description |
|------|-----------|-------------|
| `NODE_ENV` | ✅ | `development`, `staging` or `production`. |
| `NEXT_PUBLIC_HOST_ID` | ✅ | Your unique Host ID provided by the supermemory team. |
| `BETTER_AUTH_SECRET` | ✅ | Random 32-byte string – run `openssl rand -base64 32`. |
| `BETTER_AUTH_URL` | ✅ | Public base URL for the API (no trailing `/`). Example: `https://api.example.com`. |
| `DATABASE_URL` | ✅ | Postgres connection string (e.g. `postgres://user:pass@host:5432/db`). |
| `CLOUDFLARE_ACCOUNT_ID` | ✅ | Your Cloudflare account ID. |
| `CLOUDFLARE_API_TOKEN` | ✅ | Token created in *Prerequisites*. |
| `OPENAI_API_KEY` | ✅ | Key from [platform.openai.com](https://platform.openai.com). |
| `RESEND_API_KEY` | ✅ | E-mail provider key if you plan to send e-mails. |
| `ANTHROPIC_API_KEY` |  | Needed to use Claude models. |
| `GEMINI_API_KEY` |  | Key for Google Gemini models. |
| `GROQ_API_KEY` |  | Key for Groq models. |
| `AUTH_GITHUB_ID` / `AUTH_GITHUB_SECRET` |  | Enable GitHub OAuth login. |
| `AUTH_GOOGLE_ID` / `AUTH_GOOGLE_SECRET` |  | Enable Google OAuth login. |
| `GOOGLE_CLIENT_ID` / `GOOGLE_CLIENT_SECRET` |  | Needed for Google Drive connector. |
| `MICROSOFT_CLIENT_ID` / `MICROSOFT_CLIENT_SECRET` |  | Needed for OneDrive connector. |
| `NOTION_CLIENT_ID` / `NOTION_CLIENT_SECRET` |  | Needed for Notion connector. |
| `CLOUDFLARE_AI_GATEWAY_NAME` / `CLOUDFLARE_AI_GATEWAY_TOKEN` |  | Only if you want to route requests through an AI Gateway. |
| `SENTRY_DSN` |  | If you use Sentry for error reporting. |

---

## Deploy

With your `.env` in place, run the deployment script:

```bash
# Run the deployment script provided in your package
$ bun ./deploy.ts
```


---

## Updating Your Deployment

To update your supermemory deployment, follow the same process as the initial deployment described in the **Deploy** section above. You can reuse your existing `.env` file and add/remove any new environment variables as needed.

---