> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.vapi.ai/llms.txt.
> For full documentation content, see https://docs.vapi.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.vapi.ai/_mcp/server.

# Non-streaming chat

## Overview

Build a chat integration that receives complete responses after processing, perfect for batch processing, simple UIs, or when you need the full response before proceeding. Ideal for integrations where real-time display isn't essential.

**What You'll Build:**

* Simple request-response chat patterns with immediate complete responses
* Context management using `previousChatId` for linked conversations
* Basic integration with predictable response timing

For comprehensive context management options including sessions, see **[Session management](/chat/session-management)**.

## Prerequisites

* Completed [Chat quickstart](/chat/quickstart) tutorial
* Understanding of basic HTTP requests and JSON handling
* Familiarity with JavaScript/TypeScript promises or async/await

## Scenario

We'll build a help desk system for "TechFlow" that processes support messages through text chat and maintains conversation history using `previousChatId`.

***

## 1. Basic Non-Streaming Implementation

Start with a basic non-streaming chat implementation:

```bash title="Basic Non-Streaming Request"
curl -X POST https://api.vapi.ai/chat \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "assistantId": "your-assistant-id",
    "input": "I need help resetting my password"
  }'
```

Non-streaming responses come back as complete JSON objects:

```json title="Complete Chat Response"
{
  "id": "chat_123456",
  "orgId": "org_789012",
  "assistantId": "assistant_345678",
  "name": "Password Reset Help",
  "sessionId": "session_901234",
  "messages": [
    {
      "role": "user",
      "content": "I need help resetting my password"
    }
  ],
  "output": [
    {
      "role": "assistant",
      "content": "I can help you reset your password. First, let me verify your account information..."
    }
  ],
  "createdAt": "2024-01-15T09:30:00Z",
  "updatedAt": "2024-01-15T09:30:01Z"
}
```

Create a reusable function for non-streaming chat:

```typescript title="non-streaming-chat.ts"
async function sendChatMessage(
  message: string, 
  previousChatId?: string
): Promise<{ chatId: string; response: string }> {
  const response = await fetch('https://api.vapi.ai/chat', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      assistantId: 'your-assistant-id',
      input: message,
      ...(previousChatId && { previousChatId })
    })
  });

  const chat = await response.json();
  return {
    chatId: chat.id,
    response: chat.output[0].content
  };
}
```

***

## 2. Context Management with previousChatId

Use `previousChatId` to maintain context across multiple chats:

```typescript title="conversation-chain.ts"
async function createConversation() {
  let lastChatId: string | undefined;

  async function sendMessage(input: string): Promise<string> {
    const response = await fetch('https://api.vapi.ai/chat', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        assistantId: 'your-assistant-id',
        input: input,
        ...(lastChatId && { previousChatId: lastChatId })
      })
    });

    const chat = await response.json();
    lastChatId = chat.id;
    return chat.output[0].content;
  }

  return { sendMessage };
}

// Usage
const conversation = await createConversation();

const response1 = await conversation.sendMessage("Hello, I'm Alice");
console.log(response1);

const response2 = await conversation.sendMessage("What's my name?");
console.log(response2); // Should remember "Alice"
```

***

## 3. Custom Assistant Configuration

Instead of pre-created assistants, define configuration per request:

```bash title="Custom Assistant Request"
curl -X POST https://api.vapi.ai/chat \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "I need help with enterprise features",
    "assistant": {
      "model": {
        "provider": "openai",
        "model": "gpt-4o",
        "temperature": 0.7,
        "messages": [
          {
            "role": "system",
            "content": "You are a helpful technical support agent specializing in enterprise features."
          }
        ]
      }
    }
  }'
```

Build different chat handlers for different types of requests:

```typescript title="specialized-handlers.ts"
async function createSpecializedChat(systemPrompt: string) {
  return async function(userInput: string): Promise<string> {
    const response = await fetch('https://api.vapi.ai/chat', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        input: userInput,
        assistant: {
          model: {
            provider: 'openai',
            model: 'gpt-4o',
            temperature: 0.3,
            messages: [{ role: 'system', content: systemPrompt }]
          }
        }
      })
    });

    const chat = await response.json();
    return chat.output[0].content;
  };
}

const technicalSupport = await createSpecializedChat(
  "You are a technical support specialist. Ask clarifying questions and provide step-by-step troubleshooting."
);

const billingSupport = await createSpecializedChat(
  "You are a billing support specialist. Be precise about billing terms and always verify account information."
);

// Usage
const techResponse = await technicalSupport("My API requests are returning 500 errors");
const billingResponse = await billingSupport("I was charged twice this month");
```

***

## Next Steps

Enhance your non-streaming chat system further:

* **[Add streaming capabilities](/chat/streaming)** - Upgrade to real-time responses for better UX
* **[OpenAI compatibility](/chat/openai-compatibility)** - Use familiar OpenAI SDK patterns
* **[Integrate tools](/tools)** - Enable your assistant to call external APIs and databases
* **[Session management](/chat/session-management)** - Learn about advanced context management with sessions
* **[Add voice capabilities](/calls/outbound-calling)** - Extend your text chat to voice interactions

Need help? Chat with the team on our [Discord](https://discord.com/invite/pUFNcf2WmH) or mention us on [X/Twitter](https://x.com/Vapi_AI).