aboutsummaryrefslogtreecommitdiff
path: root/apps/docs/quickstart.mdx
blob: b0d12fad0b826a38a2b2ad327d5e01fee012e97f (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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
---
title: Quickstart
description: Make your first API call to Supermemory - add and retrieve memories.
---

<Tip>
**Using Vercel AI SDK?** Check out the [AI SDK integration](/ai-sdk/overview) for the cleanest implementation with `@supermemory/tools/ai-sdk`.
</Tip>

## Memory API

**Step 1.** Sign up for [Supermemory’s Developer Platform](http://console.supermemory.ai) to get the API key. Click on **API Keys -> Create API Key** to generate one.

![create api key](./images/create-api.png)

<Tabs>

    <Tab title="Python">
        **Step 2.** Install the Supermemory client

        ```python
        pip install supermemory
        ```

        **Step 3.** Run this in your terminal to create an environment variable with your API key:

        ```bash
        export SUPERMEMORY_API_KEY=“YOUR_API_KEY”
        ```

        **Step 4.** Import the module in your python file:

        ```python
        from supermemory import Supermemory
        import os


        client = Supermemory(api_key=os.environ.get("SUPERMEMORY_API_KEY"))
        ```

        **Step 5.** Add your first memory as follows:

        ```python
        # Create one rich memory about quantum computing applications
        memory_content = """Quantum computing represents a paradigm shift in computational power, leveraging quantum mechanical phenomena like superposition and entanglement to solve problems that are intractable for classical computers.


        The field emerged from theoretical work in the 1980s, when physicist Richard Feynman proposed that quantum systems could simulate other quantum systems more efficiently than classical computers. This insight led to the development of quantum algorithms like Shor's algorithm for factoring large numbers and Grover's algorithm for unstructured search problems.


        Today, quantum computing applications span multiple domains: in cryptography, quantum computers threaten current encryption standards while enabling new quantum-resistant protocols; in drug discovery, they can simulate molecular interactions with unprecedented accuracy; in optimization problems like logistics and financial modeling, they offer exponential speedups for certain classes of problems.


        Major tech companies including IBM, Google, and Microsoft have invested billions in quantum computing research, while startups like Rigetti Computing and IonQ focus on specific hardware approaches. The race for quantum advantage - demonstrating a quantum computer solving a problem faster than any classical computer - has become a key milestone in the field.


        Despite the promise, significant challenges remain: quantum decoherence, error correction, and scaling qubit counts while maintaining coherence. Researchers are exploring various approaches including superconducting qubits, trapped ions, topological qubits, and photonic systems, each with different trade-offs between coherence time, gate fidelity, and scalability."""


        # Add the memory to Supermemory
        response = client.memories.add(
            content=memory_content,
            container_tag="quantum-computing",
            metadata={
                "category": "technology-overview",
                "topic": "quantum-computing",
                "complexity": "intermediate",
                "word_count": len(memory_content.split())
            }
        )


        print(f"Memory added successfully!")
        print(f"Memory ID: {response.id}")
        print(f"Content length: {len(memory_content)} characters")
        ```

        Run your code. The output is as follows:

        ```bash
        Memory added successfully!
        Memory ID: uLtGU14SBDzfsvefYWbwe7
        Content length: 1701 characters
        ```

        **Step 6.** Search for this memory as follows:

        ```python
        results = client.search.memories(q="what are some applications of quantum computing?", limit=3)


        print(results)
        ```
        The output is as follows:

        ```bash
        SearchMemoriesResponse(
            results=[
                Result(
                    id="Bn1uc1yQdw3Huf8oitruwF",
                    memory="Quantum computing applications include cryptography (threatening current encryption standards, enabling quantum-resistant protocols), drug discovery (simulating molecular interactions), and optimization problems (logistics, financial modeling, offering exponential speedups).",
                    metadata=None,
                    similarity=0.7920647723809932,
                    updated_at=datetime.datetime(
                        2025, 8, 24, 5, 41, 55, 87000, tzinfo=datetime.timezone.utc
                    ),
                    context=ResultContext(children=[], parents=[]),
                    documents=None,
                    version=1.0,
                    updatedAt="2025-08-24T05:41:55.087Z",
                    rootMemoryId="Bn1uc1yQdw3Huf8oitruwF",
                ),
                Result(
                    id="4aCa4oM8praVBCWdNksjxf",
                    memory="Quantum computing is a paradigm shift in computational power, leveraging quantum mechanical phenomena like superposition and entanglement to solve problems intractable for classical computers.",
                    metadata=None,
                    similarity=0.7198909950191389,
                    updated_at=datetime.datetime(
                        2025, 8, 24, 5, 41, 55, 87000, tzinfo=datetime.timezone.utc
                    ),
                    context=ResultContext(children=[], parents=[]),
                    documents=None,
                    version=1.0,
                    updatedAt="2025-08-24T05:41:55.087Z",
                    rootMemoryId="4aCa4oM8praVBCWdNksjxf",
                ),
                Result(
                    id="8vzhZhBCuqyrLNXtzBDx7y",
                    memory="IBM, Google, and Microsoft have invested billions in quantum computing research.",
                    metadata=None,
                    similarity=0.6960905375426799,
                    updated_at=datetime.datetime(
                        2025, 8, 24, 5, 41, 55, 87000, tzinfo=datetime.timezone.utc
                    ),
                    context=ResultContext(children=[], parents=[]),
                    documents=None,
                    version=1.0,
                    updatedAt="2025-08-24T05:41:55.087Z",
                    rootMemoryId="8vzhZhBCuqyrLNXtzBDx7y",
                ),
            ],
            timing=214.0,
            total=3.0,
        )
        ```
        Awesome! Now that you’ve made your first request, explore all of Supermemory’s features in detail and how you can use them in your app.
    </Tab>

    <Tab title="Typescript">
        **Step 2.** Install the Supermemory dependency:

        ```bash
        npm install supermemory
        ```

        **Step 3.** Set the environment variable:

        ```bash
        export SUPERMEMORY_API_KEY="your_actual_api_key_here"
        ```
        **Step 4.** Create a `quickstart.ts` file and import the package:

        ```ts
        import 'dotenv/config';
        import Supermemory from 'supermemory';


        const client = new Supermemory({
        apiKey: process.env.SUPERMEMORY_API_KEY});
        ```

        **Step 5.** Add a memory:

        ```ts

        const memoryContent = `Quantum computing represents a paradigm shift in computational power, leveraging quantum mechanical phenomena like superposition and entanglement to solve problems that are intractable for classical computers.


        The field emerged from theoretical work in the 1980s, when physicist Richard Feynman proposed that quantum systems could simulate other quantum systems more efficiently than classical computers. This insight led to the development of quantum algorithms like Shor's algorithm for factoring large numbers and Grover's algorithm for unstructured search problems.


        Today, quantum computing applications span multiple domains: in cryptography, quantum computers threaten current encryption standards while enabling new quantum-resistant protocols; in drug discovery, they can simulate molecular interactions with unprecedented accuracy; in optimization problems like logistics and financial modeling, they offer exponential speedups for certain classes of problems.


        Major tech companies including IBM, Google, and Microsoft have invested billions in quantum computing research, while startups like Rigetti Computing and IonQ focus on specific hardware approaches. The race for quantum advantage - demonstrating a quantum computer solving a problem faster than any classical computer - has become a key milestone in the field.


        Despite the promise, significant challenges remain: quantum decoherence, error correction, and scaling qubit counts while maintaining coherence. Researchers are exploring various approaches including superconducting qubits, trapped ions, topological qubits, and photonic systems, each with different trade-offs between coherence time, gate fidelity, and scalability.`;


        async function addMemory() {
            try {
                const response = await client.memories.add({
                    content: memoryContent,
                    containerTag: "quantum-computing",
                    metadata: {
                    category: "technology-overview",
                    topic: "quantum-computing",
                    complexity: "intermediate",
                    wordCount: memoryContent.split(' ').length
                    }
                });
                console.log("Memory added successfully!");
                console.log(`Memory ID: ${response.id}`);
                return response.id
            } catch (error) {
                console.error("Error adding memory:", error);
                throw error;
            }
        }
        ```

        Running this code block gives the following output:

        ```bash

        Memory added successfully!
        Memory ID: adMxzQgSxo37jq6kjpsFMg
        ```

        **Step 6.** Search for your memory using natural language:

        ```ts
        async function searchMemories() {
            try {
                const results = await client.search.memories({
                    q: "what are some applications of quantum computing?",
                    limit: 3
                });

                console.log('Search results:', results);

                return results;
            } catch (error) {
                console.error('Error searching memories:', error);
            }
        }
        ```

        The output is as follows:

        ```bash
        Search results: {
            results: [
                {
                    id: 'Bn1uc1yQdw3Huf8oitruwF',
                    memory: 'Quantum computing applications include cryptography (threatening current encryption standards, enabling quantum-resistant protocols), drug discovery (simulating molecular interactions), and optimization problems (logistics, financial modeling, offering exponential speedups).',
                    metadata: null,
                    updatedAt: '2025-08-24T05:41:55.087Z',
                    version: 1,
                    rootMemoryId: 'Bn1uc1yQdw3Huf8oitruwF',
                    similarity: 0.7920647723809932,
                    context: [Object]
                },
                {
                    id: '4aCa4oM8praVBCWdNksjxf',
                    memory: 'Quantum computing is a paradigm shift in computational power, leveraging quantum mechanical phenomena like superposition and entanglement to solve problems intractable for classical computers.',
                    metadata: null,
                    updatedAt: '2025-08-24T05:41:55.087Z',
                    version: 1,
                    rootMemoryId: '4aCa4oM8praVBCWdNksjxf',
                    similarity: 0.7198909950191389,
                    context: [Object]
                },
                {
                    id: '8vzhZhBCuqyrLNXtzBDx7y',
                    memory: 'IBM, Google, and Microsoft have invested billions in quantum computing research.',
                    metadata: null,
                    updatedAt: '2025-08-24T05:41:55.087Z',
                    version: 1,
                    rootMemoryId: '8vzhZhBCuqyrLNXtzBDx7y',
                    similarity: 0.6960905375426799,
                    context: [Object]
                }
            ],
            timing: 216,
            total: 3
        }
        ```
        As you can see, Supermemory automatically chunked the main memory into smaller parts and returned them. You can visually see that in the graph in the console:

        ![graph view](./images/graph-view.png)

        Now that you’ve made your first request, explore all of Supermemory’s features in detail and how you can use them in your app.
    </Tab>

    <Tab title="cURL">
        **Step 2.** The base URL for requests is as follows:

        ```bash
        https://api.supermemory.ai/
        ```

        **Step 3.** Set the environment variable:

        ```bash
        export SUPERMEMORY_API_KEY="your_api_key"
        ```

        **Step 4.** Add a memory as follows:

        ```bash
        curl -X POST "https://api.supermemory.ai/v3/documents" \
          -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "content": "Quantum computing represents a paradigm shift in computational power, leveraging quantum mechanical phenomena like superposition and entanglement to solve problems that are intractable for classical computers. The field emerged from theoretical work in the 1980s, when physicist Richard Feynman proposed that quantum systems could simulate other quantum systems more efficiently than classical computers. This insight led to the development of quantum algorithms like Shor'\''s algorithm for factoring large numbers and Grover'\''s algorithm for unstructured search problems. Today, quantum computing applications span multiple domains: in cryptography, quantum computers threaten current encryption standards while enabling new quantum-resistant protocols; in drug discovery, they can simulate molecular interactions with unprecedented accuracy; in optimization problems like logistics and financial modeling, they offer exponential speedups for certain classes of problems. Major tech companies including IBM, Google, and Microsoft have invested billions in quantum computing research, while startups like Rigetti Computing and IonQ focus on specific hardware approaches. The race for quantum advantage - demonstrating a quantum computer solving a problem faster than any classical computer - has become a key milestone in the field. Despite the promise, significant challenges remain: quantum decoherence, error correction, and scaling qubit counts while maintaining coherence. Researchers are exploring various approaches including superconducting qubits, trapped ions, topological qubits, and photonic systems, each with different trade-offs between coherence time, gate fidelity, and scalability.",
            "containerTag": "quantum-computing",
            "metadata": {
              "category": "technology-overview",
              "topic": "quantum-computing",
              "complexity": "intermediate",
              "wordCount": 156
            }
          }'
        ```

        The response is as follows:

        ```json
        {"id":"D2Ar7Vo7ub83w3PRPZcaP1","status":"queued"}
        ```

        **Step 5.** Search for this memory using natural language:

        ```bash
        curl -X POST "https://api.supermemory.ai/v4/search" \
          -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "q": "what are some applications of quantum computing?",
            "limit": 3
          }'
        ```

        The result is as follows:

        ```json
        {
          "results": [
            {
              "id": "Bn1uc1yQdw3Huf8oitruwF",
              "memory": "Quantum computing applications include cryptography (threatening current encryption standards, enabling quantum-resistant protocols), drug discovery (simulating molecular interactions), and optimization problems (logistics, financial modeling, offering exponential speedups).",
              "metadata": null,
              "updatedAt": "2025-08-24T05:41:55.087Z",
              "version": 1,
              "rootMemoryId": "Bn1uc1yQdw3Huf8oitruwF",
              "similarity": 0.7920647723809932,
              "context": {
                "parents": [],
                "children": []
              }
            },
            {
              "id": "4aCa4oM8praVBCWdNksjxf",
              "memory": "Quantum computing is a paradigm shift in computational power, leveraging quantum mechanical phenomena like superposition and entanglement to solve problems intractable for classical computers.",
              "metadata": null,
              "updatedAt": "2025-08-24T05:41:55.087Z",
              "version": 1,
              "rootMemoryId": "4aCa4oM8praVBCWdNksjxf",
              "similarity": 0.7198909950191389,
              "context": {
                "parents": [],
                "children": []
              }
            },
            {
              "id": "8vzhZhBCuqyrLNXtzBDx7y",
              "memory": "IBM, Google, and Microsoft have invested billions in quantum computing research.",
              "metadata": null,
              "updatedAt": "2025-08-24T05:41:55.087Z",
              "version": 1,
              "rootMemoryId": "8vzhZhBCuqyrLNXtzBDx7y",
              "similarity": 0.6960905375426799,
              "context": {
                "parents": [],
                "children": []
              }
            }
          ],
          "timing": 363,
          "total": 3
        }
        ```

        And that's it! Good job!

    </Tab>
</Tabs>


## Memory Router
Learn how you can add the Memory Router to your existing LLM requests.

The memory router works as a proxy on top of LLM calls. When conversations get very long, it automatically chunks them for optimal performance, retrieves the most relevant information from the history, and balances token usage + cost.

The best part is that it requires no changes to your application logic. Here’s how to get started:

**Step 1.** Sign up for [Supermemory’s Developer Platform](http://console.supermemory.ai) to get the API key. Click on **API Keys -> Create API Key** to generate one.

**Step 2.** Get your LLM provider’s API key

- [OpenAI](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key)
- [Gemini](https://ai.google.dev/gemini-api/docs/api-key)
- [Anthropic](https://docs.anthropic.com/en/api/admin-api/apikeys/get-api-key)
- [Groq](https://console.groq.com/keys)

**Step 3.** Append Supermemory’s URL to your LLM provider’s OpenAI-compatible API URL:

<CodeGroup>

```bash OpenAI
https://api.supermemory.ai/v3/https://api.openai.com/v1/
```
```bash Anthropic
https://api.supermemory.ai/v3/https://api.anthropic.com/v1/
```

```bash Gemini
https://api.supermemory.ai/v3/https://generativelanguage.googleapis.com/v1beta/openai/
```

```bash Groq
https://api.supermemory.ai/v3/https://api.groq.com/openai/v1
```

```bash Others
https://api.supermemory.ai/v3/[openai-api-url-here]
```
</CodeGroup>

<Tabs>


<Tab title="Typescript">
    **Step 4.** Install the dependencies

    ```bash
    npm install openai
    ```

    **Step 5.** Set two environment variables in your environment: one for Supermemory, and one for your model provider.

    ```bash
    export SUPERMEMORY_API_KEY=“your_api_key_here”

    # export OPENAI_API_KEY/ANTHROPIC_API_KEY/GEMINI_API_KEY/GROQ_API_KEY=“api_key_here” (based on your model)
    ```

    **Step 6.** Send a request to the updated endpoint:

    <CodeGroup>

    ```ts OpenAI
    import OpenAI from 'openai';

    const client = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY,
    baseURL: 'https://api.supermemory.ai/v3/https://api.openai.com/v1',
    defaultHeaders: {
        'x-supermemory-api-key': process.env.SUPERMEMORY_API_KEY!,
        'x-sm-user-id': 'user_123' // Your user identifier
    }
    });

    async function chatWithOpenAI() {
    try {
        const response = await client.chat.completions.create({
        model: 'gpt-5',
        messages: [
            { role: 'user', content: 'Hello my name is Naman. How are you?' }
        ],
        max_tokens: 1000,
        temperature: 0.7
        });

        console.log('OpenAI Response:', response.choices[0].message.content);
        return response;
    } catch (error) {
        console.error('Error with OpenAI:', error);
    }
    }

    ```
    ```ts Anthropic
    import OpenAI from 'openai';

    const anthropicClient = new OpenAI({
    apiKey: process.env.ANTHROPIC_API_KEY,
    baseURL: 'https://api.supermemory.ai/v3/https://api.anthropic.com/v1',
    defaultHeaders: {
        'x-supermemory-api-key': process.env.SUPERMEMORY_API_KEY!,
        'x-sm-user-id': 'user_123'
    }
    });

    async function chatWithClaude() {
    try {
        const response = await anthropicClient.chat.completions.create({
        model: 'claude-3-sonnet-20240229',
        messages: [
            { role: 'user', content: 'Hello my name is Naman. How are you?' }
        ],
        max_tokens: 1000
        });

        console.log('Claude Response:', response.choices[0].message.content);
        return response;
    } catch (error) {
        console.error('Error with Claude:', error);
    }
    }
    ```

    ```ts Gemini

    import OpenAI from 'openai';

    const geminiClient = new OpenAI({
    apiKey: process.env.GEMINI_API_KEY,
    baseURL: 'https://api.supermemory.ai/v3/https://generativelanguage.googleapis.com/v1beta',
    defaultHeaders: {
        'x-supermemory-api-key': process.env.SUPERMEMORY_API_KEY!,
        'x-sm-user-id': 'user_123'
    }
    });

    async function chatWithGemini() {
    try {
        const response = await geminiClient.chat.completions.create({
        model: 'gemini-pro',
        messages: [
            { role: 'user', content: 'Hello my name is Naman. How are you?' }
        ],
        max_tokens: 1000
        });

        console.log('Gemini Response:', response.choices[0].message.content);
        return response;
    } catch (error) {
        console.error('Error with Gemini:', error);
    }
    }

    ```

    ```ts Groq

    import OpenAI from 'openai';

    const groqClient = new OpenAI({
    apiKey: process.env.GROQ_API_KEY,
    baseURL: 'https://api.supermemory.ai/v3/https://api.groq.com/openai/v1',
    defaultHeaders: {
        'x-supermemory-api-key': process.env.SUPERMEMORY_API_KEY!,
        'x-sm-user-id': 'user_123'
    }
    });

    async function chatWithGroq() {
    try {
        const response = await groqClient.chat.completions.create({
        model: 'mixtral-8x7b-32768',
        messages: [
            { role: 'user', content: 'Hello my name is Naman. How are you?' }
        ],
        max_tokens: 1000
        });

        console.log('Groq Response:', response.choices[0].message.content);
        return response;
    } catch (error) {
        console.error('Error with Groq:', error);
    }
    }


    ```

    </CodeGroup>

    Each of these code snippets changes the Base URL based on the OpenAI-compatible API URL given by the model providers. Some of the key parameters to note are:

    - `apiKey`: Your model provider’s API key
    - `x-supermemory-api-key`: Your Supermemory API key
    - `x-sm-user-id`: Scope conversations by user with a user ID. This will enable cross-conversation memory, meaning users can reference other chats and draw information from them.

    Additionally, while not shown in this quickstart, you can also pass an `x-sm-conversation-id` header.

    Then, you won’t have to send the entire array of messages to the LLM as conversation history. Supermemory will handle it.

    If you run the above code blocks, you’ll get an output from your LLM like this:

    ```
    “Hello, Naman! I'm just a computer program, so I don't have feelings, but I'm here and ready to help you. How can I assist you today?”
    ```

    After that, if you modify the request to ask, ‘What is my name?’ instead, you’ll get the following response:

    ```
    Your name is Naman.
    ```

    Thus, the memory router is working!
</Tab>

<Tab title="Python">
        **Step 4.** Install the Python dependency:

        ```
        pip install openai
        ```

        **Step 5.** Set two environment variables in your environment: one for Supermemory and one for your model provider.

        ```bash
        export SUPERMEMORY_API_KEY=“your_api_key_here”

        # export OPENAI_API_KEY/ANTHROPIC_API_KEY/GEMINI_API_KEY/GROQ_API_KEY=“api_key_here” (based on your model)
        ```

        **Step 6.** Send a request to the LLM with the updated base URL and parameters:

        <CodeGroup>

        ```python OpenAI
        import os
        from openai import OpenAI

        client = OpenAI(
            api_key=os.getenv("OPENAI_API_KEY"),
            base_url="https://api.supermemory.ai/v3/https://api.openai.com/v1",
            default_headers={
                "x-supermemory-api-key": os.getenv("SUPERMEMORY_API_KEY"),
                "x-sm-user-id": "user_123"
            }
        )

        def chat_with_openai():
            try:
                response = client.chat.completions.create(
                    model="gpt-5",
                    messages=[
                        {"role": "user", "content": "Hello my name is Naman. How are you?"}
                    ],
                    max_tokens=1000,
                    temperature=0.7
                )

                print("OpenAI Response:", response.choices[0].message.content)
                return response
            except Exception as error:
                print(f"Error with OpenAI: {error}")

        ```
        ```python Anthropic
        from openai import OpenAI

        anthropic_client = OpenAI(
            api_key=os.getenv("ANTHROPIC_API_KEY"),
            base_url="https://api.supermemory.ai/v3/https://api.anthropic.com/v1",
            default_headers={
                "x-supermemory-api-key": os.getenv("SUPERMEMORY_API_KEY"),
                "x-sm-user-id": "user_123"
            }
        )

        def chat_with_claude():
            try:
                response = anthropic_client.chat.completions.create(
                    model="claude-3-sonnet-20240229",
                    messages=[
                        {"role": "user", "content": "Hello my name is Naman. How are you?"}
                    ],
                    max_tokens=1000
                )

                print("Claude Response:", response.choices[0].message.content)
                return response
            except Exception as error:
                print(f"Error with Claude: {error}")

        ```

        ```python Gemini
        from openai import OpenAI

        gemini_client = OpenAI(
            api_key=os.getenv("GEMINI_API_KEY"),
            base_url="https://api.supermemory.ai/v3/https://generativelanguage.googleapis.com/v1beta",
            default_headers={
                "x-supermemory-api-key": os.getenv("SUPERMEMORY_API_KEY"),
                "x-sm-user-id": "user_123"
            }
        )

        def chat_with_gemini():
            try:
                response = gemini_client.chat.completions.create(
                    model="gemini-pro",
                    messages=[
                        {"role": "user", "content": "Hello my name is Naman. How are you?"}
                    ],
                    max_tokens=1000
                )

                print("Gemini Response:", response.choices[0].message.content)
                return response
            except Exception as error:
                print(f"Error with Gemini: {error}")
        ```

        ```python Groq
        from openai import OpenAI

        groq_client = OpenAI(
            api_key=os.getenv("GROQ_API_KEY"),
            base_url="https://api.supermemory.ai/v3/https://api.groq.com/openai/v1",
            default_headers={
                "x-supermemory-api-key": os.getenv("SUPERMEMORY_API_KEY"),
                "x-sm-user-id": "user_123"
            }
        )

        def chat_with_groq():
            try:
                response = groq_client.chat.completions.create(
                    model="mixtral-8x7b-32768",
                    messages=[
                        {"role": "user", "content": "Hello my name is Naman. How are you?"}
                    ],
                    max_tokens=1000
                )

                print("Groq Response:", response.choices[0].message.content)
                return response
            except Exception as error:
                print(f"Error with Groq: {error}")
        ```

        </CodeGroup>

        Each of these code snippets changes the Base URL based on the OpenAI-compatible API URL given by the model providers. Some of the key parameters to note are:

        - `api_key`: Your model provider’s API key
        - `x-supermemory-api-key`: Your Supermemory API key
        - `x-sm-user-id`: Scope conversations by user with a user ID. This will enable cross-conversation memory, meaning users can reference other chats and draw information from them.

        Additionally, while not shown in this quickstart, you can also pass an `x-sm-conversation-id` header.

        Then, you won’t have to send the entire array of messages to the LLM as conversation history. Supermemory will handle it.

        If you run the above code blocks, you’ll get an output from your LLM like this:

        ```
        “Hello, Naman! I'm just a computer program, so I don't have feelings, but I'm here and ready to help you. How can I assist you today?”
        ```

        After that, if you modify the request to ask, ‘What is my name?’ instead, you’ll get the following response:

        ```
        Your name is Naman.
        ```

        Thus, the memory router is working!
    </Tab>
    <Tab title="cURL">
        **Step 4.** Set the environment variables:

        ```bash
        export SUPERMEMORY_API_KEY="your_supermemory_api_key"
        export OPENAI_API_KEY="your_openai_api_key"
        export ANTHROPIC_API_KEY="your_anthropic_api_key"
        export GEMINI_API_KEY="your_gemini_api_key"
        export GROQ_API_KEY="your_groq_api_key"
        ```

        **Step 5.** Send a request to the LLM with the updated base URL and parameters:

        <CodeGroup>
        ```bash OpenAI
        curl https://api.supermemory.ai/v3/https://api.openai.com/v1/chat/completions \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer $OPENAI_API_KEY" \
        -H "x-supermemory-api-key: $SUPERMEMORY_API_KEY" \
        -H "x-sm-user-id: user_123" \
        -d '{
            "model": "gpt-5",
            "messages": [
            {"role": "user", "content": "Hello my name is Naman. How are you?"}
            ],
            "max_tokens": 1000,
            "temperature": 0.7
        }'
        ```

        ```bash Claude
        curl https://api.supermemory.ai/v3/https://api.anthropic.com/v1/messages \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer $ANTHROPIC_API_KEY" \
        -H "x-supermemory-api-key: $SUPERMEMORY_API_KEY" \
        -H "x-sm-user-id: user_123" \
        -d '{
            "model": "claude-3-sonnet-20240229",
            "messages": [
            {"role": "user", "content": "Hello my name is Naman. How are you?"}
            ],
            "max_tokens": 1000
        }'
        ```

        ```bash Gemini
        curl https://api.supermemory.ai/v3/https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer $GEMINI_API_KEY" \
        -H "x-supermemory-api-key: $SUPERMEMORY_API_KEY" \
        -H "x-sm-user-id: user_123" \
        -d '{
            "contents": [
            {
                "parts": [
                {"text": "Hello my name is Naman. How are you?"}
                ]
            }
            ],
            "generationConfig": {
            "maxOutputTokens": 1000
            }
        }'
        ```

        ```bash Groq
        curl https://api.supermemory.ai/v3/https://api.groq.com/openai/v1/chat/completions \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer $GROQ_API_KEY" \
        -H "x-supermemory-api-key: $SUPERMEMORY_API_KEY" \
        -H "x-sm-user-id: user_123" \
        -d '{
            "model": "mixtral-8x7b-32768",
            "messages": [
            {"role": "user", "content": "Hello my name is Naman. How are you?"}
            ],
            "max_tokens": 1000
        }'
        ```
        </CodeGroup>

        Each of these code snippets changes the Base URL based on the OpenAI-compatible API URL given by the model providers. Some of the key parameters to note are:

        - **Authorization header**: Your model provider’s API key
        - `x-supermemory-api-key`: Your Supermemory API key
        - `x-sm-user-id`: Scope conversations by user with a user ID. This will enable cross-conversation memory, meaning users can reference other chats and draw information from them.

        Additionally, while not shown in this quickstart, you can also pass an `x-sm-conversation-id` header.

        Then, you won’t have to send the entire array of messages to the LLM as conversation history. Supermemory will handle it.

        If you run the above code blocks, you’ll get an output from your LLM like this:

        ```
        “Hello, Naman! I'm just a computer program, so I don't have feelings, but I'm here and ready to help you. How can I assist you today?”
        ```

        After that, if you modify the request to ask, ‘What is my name?’ instead, you’ll get the following response:

        ```
        Your name is Naman.
        ```

        Thus, the memory router is working!
    </Tab>
</Tabs>


For additional reference, here are links to the model providers’ documentation:
- [OpenAI API Reference](https://platform.openai.com/docs/api-reference)
- [Anthropic Claude API](https://docs.anthropic.com/claude/reference)
- [Google Gemini API](https://ai.google.dev/docs)
- [Groq API Documentation](https://console.groq.com/docs)