# TypeScript

Build AI applications with TypeScript or JavaScript using the Graphlit SDK.

{% hint style="info" %}
**New to Graphlit?** Complete the [Quickstart tutorial](/getting-started/quickstart.md) for a hands-on introduction.
{% endhint %}

***

## Installation

Install the Graphlit client with npm or yarn:

{% tabs %}
{% tab title="npm" %}

```bash
npm install graphlit-client
```

{% endtab %}

{% tab title="yarn" %}

```bash
yarn add graphlit-client
```

{% endtab %}

{% tab title="pnpm" %}

```bash
pnpm add graphlit-client
```

{% endtab %}
{% endtabs %}

**Requirements:**

* Node.js 20 or higher (Docker: use `node:20-slim` or `node:22-slim`)
* Graphlit account with [API credentials](/account-setup-one-time/create-project.md)

***

## Quick Start

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { Graphlit } from 'graphlit-client';

async function main() {
  const graphlit = new Graphlit();

  const response = await graphlit.ingestText(
    'Our AI agent needs persistent memory across sessions...',
    'Product Requirements',
  );

  console.log(`✅ Memory created: ${response.ingestText.id}`);
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
});
```

{% endtab %}

{% tab title="JavaScript (ESM)" %}

```javascript
import { Graphlit } from 'graphlit-client';

async function main() {
  const graphlit = new Graphlit();

  const response = await graphlit.ingestText(
    'Our AI agent needs persistent memory across sessions...',
    'Product Requirements'
  );

  console.log(`✅ Memory created: ${response.ingestText.id}`);
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
});
```

{% endtab %}

{% tab title="JavaScript (CommonJS)" %}

```javascript
require('dotenv/config');
const { Graphlit } = require('graphlit-client');

async function main() {
  const graphlit = new Graphlit();

  const response = await graphlit.ingestText(
    'Our AI agent needs persistent memory across sessions...',
    'Product Requirements'
  );

  console.log(`✅ Memory created: ${response.ingestText.id}`);
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
});
```

{% endtab %}
{% endtabs %}

{% hint style="success" %}
**That's it!** You now have semantic memory for your AI application.
{% endhint %}

***

## Configuration Options

### Environment Variables (Recommended)

```typescript
import { Graphlit } from 'graphlit-client';

const graphlit = new Graphlit();
```

{% hint style="warning" %}
**Security:** Never commit credentials to git. Use environment variables or secrets management in production.
{% endhint %}

### Alternative: Explicit Configuration

Only use if you need to override environment variables:

```typescript
import { Graphlit } from 'graphlit-client';

const graphlit = new Graphlit({
  organizationId: process.env.GRAPHLIT_ORGANIZATION_ID,
  environmentId: process.env.GRAPHLIT_ENVIRONMENT_ID,
  jwtSecret: process.env.GRAPHLIT_JWT_SECRET,
});
```

***

## Common Patterns

### Ingest Content

```typescript
// From URL
const pdf = await graphlit.ingestUri(
  'https://example.com/document.pdf',
  'Product Brief',
  undefined, // id
  undefined, // identifier
  true,      // isSynchronous
);

console.log(`📄 PDF ready: ${pdf.ingestUri.id}`);

// From text
const notes = await graphlit.ingestText(
  'Discussion about Q4 planning...',
  'Meeting Notes',
);

console.log(`📝 Notes ready: ${notes.ingestText.id}`);
```

### Search Memory

```typescript
const response = await graphlit.queryContents({
  search: 'quarterly planning'
});

for (const content of response.contents?.results ?? []) {
  console.log(`📄 ${content.name}`);
}
```

### Chat with Context

```typescript
// Create conversation
const conversation = await graphlit.createConversation({
  name: 'AI Assistant',
});

// Ask questions
const answer = await graphlit.promptConversation(
  'What did we discuss about Q4 planning?',
  conversation.createConversation.id,
);

console.log(answer.promptConversation.message?.message);
```

***

## Next Steps

**Quickstarts:**

* [Quickstart: Your First Agent](/getting-started/quickstart.md) - Build a streaming agent in 7 minutes
* [AI Agents](/tutorials/ai-agents.md) - Create agents with persistent memory
* [MCP Integration](/mcp-integration/mcp-integration.md) - Connect to your IDE

**Examples:**

* [Next.js Applications](https://github.com/graphlit/graphlit-samples/tree/main/nextjs) - Full-stack chat apps
* [MCP Server](https://github.com/graphlit/graphlit-mcp-server) - Production MCP implementation

**Resources:**

* [TypeScript SDK on GitHub](https://github.com/graphlit/graphlit-client-typescript)
* [Use Case Library](/api-guides/use-cases.md) - 100+ code examples
* [Ask Graphlit](/resources/ask-graphlit.md) - AI code assistant
* [Join Discord](https://discord.gg/ygFmfjy3Qx) - Get help from the community


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.graphlit.dev/sdk-setup/for-typescript-developers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
