> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mycura.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Build your first AI health conversation in 5 minutes

<Note>
  **Recommended Approach:** Use conversation threads for the best experience. They handle context automatically so you can focus on building great features.
</Note>

## Quick Integration Guide

Get up and running with the Cura AI API in just a few steps using **conversation threads** - the easiest way to build multi-turn conversations.

### Step 1: Authentication

All API requests require authentication. Add your API key to request headers:

```bash theme={null}
X-API-Key: YOUR_API_KEY
```

<Info>
  **Base URL:** `https://api.mycura.org/api/cura`

  Learn more about [authentication](/authentication).
</Info>

### Step 2: Create a Conversation Thread

Start by creating a thread - it acts as a container for your conversation with automatic context management.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.mycura.org/api/cura/threads" \
    -H "X-API-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "phone": "5551234567"
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.mycura.org/api/cura/threads', {
    method: 'POST',
    headers: {
      'X-API-Key': 'YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      phone: '5551234567'
    })
  });

  const { threadId } = await response.json();
  // Save this threadId for the conversation!
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.mycura.org/api/cura/threads',
      json={'phone': '5551234567'},
      headers={'X-API-Key': 'YOUR_API_KEY'}
  )

  thread_id = response.json()['threadId']
  # Save this thread_id for the conversation!
  ```
</CodeGroup>

**Response:**

```json theme={null}
{
  "success": true,
  "threadId": "82451",
  "expiresAt": "2025-10-22T19:30:00.000Z",
  "message": "Thread created successfully. Use this threadId in your chat requests."
}
```

### Step 3: Send Messages with Auto-Context

Now use the `threadId` to send messages. The AI automatically remembers your conversation!

<CodeGroup>
  ```bash cURL theme={null}
  # Message 1
  curl -X POST "https://api.mycura.org/api/cura/chat" \
    -H "X-API-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "threadId": "82451",
      "message": "I have been experiencing headaches"
    }'

  # Message 2 - AI remembers message 1 automatically!
  curl -X POST "https://api.mycura.org/api/cura/chat" \
    -H "X-API-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "threadId": "82451",
      "message": "What could be causing them?"
    }'
  ```

  ```javascript Node.js theme={null}
  // Message 1
  let response = await fetch('https://api.mycura.org/api/cura/chat', {
    method: 'POST',
    headers: {
      'X-API-Key': 'YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      threadId: '82451',
      message: 'I have been experiencing headaches'
    })
  });

  console.log((await response.json()).response);

  // Message 2 - AI remembers message 1 automatically!
  response = await fetch('https://api.mycura.org/api/cura/chat', {
    method: 'POST',
    headers: {
      'X-API-Key': 'YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      threadId: '82451',
      message: 'What could be causing them?'
    })
  });

  console.log((await response.json()).response);
  ```

  ```python Python theme={null}
  # Message 1
  response = requests.post(
      'https://api.mycura.org/api/cura/chat',
      json={
          'threadId': '82451',
          'message': 'I have been experiencing headaches'
      },
      headers={'X-API-Key': 'YOUR_API_KEY'}
  )

  print(response.json()['response'])

  # Message 2 - AI remembers message 1 automatically!
  response = requests.post(
      'https://api.mycura.org/api/cura/chat',
      json={
          'threadId': '82451',
          'message': 'What could be causing them?'
      },
      headers={'X-API-Key': 'YOUR_API_KEY'}
  )

  print(response.json()['response'])
  ```
</CodeGroup>

**Response:**

```json theme={null}
{
  "success": true,
  "response": "Headaches can be caused by stress, dehydration, lack of sleep...",
  "threadId": "82451",
  "messageCount": 4
}
```

<Check>
  **That's it!** The AI automatically maintains conversation context. No need to manually send conversation history arrays.
</Check>

## Why Use Threads?

<CardGroup cols={2}>
  <Card title="Automatic Context" icon="brain">
    Server manages the last 20 messages for you - no manual history tracking
  </Card>

  <Card title="Isolated Conversations" icon="lock">
    Each thread is independent - perfect for multiple users or topics
  </Card>

  <Card title="Auto-Cleanup" icon="clock">
    Threads expire after 30 minutes of inactivity for privacy
  </Card>

  <Card title="Patient Linking" icon="link">
    Optional patient linking gives AI medical context automatically
  </Card>
</CardGroup>

## Alternative: Manual Context (Not Recommended)

You can also use the chat endpoint without threads, but you'll need to manually manage conversation history:

<CodeGroup>
  ```bash cURL (Manual) theme={null}
  curl -X POST "https://api.mycura.org/api/cura/chat" \
    -H "X-API-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "message": "What could be causing them?",
      "conversationHistory": [
        {"role": "user", "content": "I have headaches"},
        {"role": "assistant", "content": "...previous response..."}
      ]
    }'
  ```

  ```javascript Node.js (Manual) theme={null}
  // You must manually track and send history
  const history = [];

  // Message 1
  let resp = await chat({ message: 'I have headaches' });
  history.push({ role: 'user', content: 'I have headaches' });
  history.push({ role: 'assistant', content: resp.response });

  // Message 2 - must send full history manually
  resp = await chat({ 
    message: 'What causes them?',
    conversationHistory: history 
  });
  ```
</CodeGroup>

<Warning>
  Manual context management is more complex and error-prone. We strongly recommend using threads instead.
</Warning>

## Next Steps

Now that you've built your first conversation with threads, dive deeper:

<CardGroup cols={2}>
  <Card title="Conversation Threads Guide" icon="messages" href="/conversation-threads">
    Complete guide to thread features, best practices, and advanced usage.
  </Card>

  <Card title="Thread API Reference" icon="code" href="/api-reference/endpoint/create-thread">
    Detailed documentation for all thread management endpoints.
  </Card>

  <Card title="Patient Management" icon="user-doctor" href="/api-reference/endpoint/create-patient">
    Create and manage patient records for richer AI context.
  </Card>

  <Card title="Best Practices" icon="lightbulb" href="/best-practices">
    Production tips, error handling, and optimization techniques.
  </Card>
</CardGroup>

## OpenAPI Specification

Access the complete OpenAPI specification at:

```
https://api.mycura.org/cura/openapi.json
```

This can be imported into tools like Postman, Insomnia, or used to generate client libraries.
