# Context Endpoint

Retrieve context-aware responses from your connected knowledge sources.

## Quick reference

| Property | Value |
|----------|-------|
| **Endpoint** | `GET /api/v1/context` |
| **Authentication** | API key via `Authorization` header |
| **Rate limit** | 5 requests per 10 seconds |
| **Response format** | JSON |
| **Cache duration** | 1 hour per unique query + mode combination |

### Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `query` | string | Yes | The question or search query. Dashes and underscores are converted to spaces. |
| `mode` | string | No | Optional mode name to weight results (e.g. `customer-support`). Spaces and underscores are normalized to dashes. |

### Status codes

| Code | Description |
|------|-------------|
| `200` | Query successful |
| `400` | Query parameter is missing |
| `401` | API key is missing or subscription required |
| `404` | API key is invalid |
| `429` | Rate limit exceeded |

## Examples

### Basic usage

Query your connected knowledge sources with a simple GET request:

```bash
curl -X GET "https://context-link.ai/api/v1/context?query=what-is-RAG" \
     -H "Authorization: your-api-key-here"
```

**Response:**

```json
{
    "message": "RAG (Retrieval-Augmented Generation) is...",
    "format": "markdown"
}
```

### With mode

Weight results toward a specific mode configured on your Connections page:

```bash
curl -X GET "https://context-link.ai/api/v1/context?query=what-is-RAG&mode=customer-support" \
     -H "Authorization: your-api-key-here"
```

Modes let you create named weighting profiles so the same connections can be prioritized differently depending on use case.

### Query formatting

Dashes and underscores in queries are automatically converted to spaces:

```bash
# These queries are equivalent:
?query=hello-world
?query=hello_world
?query=hello%20world

# All become: "hello world"
```

### Python example

```python
import requests

api_key = "your-api-key-here"
query = "what is context link"

response = requests.get(
    "https://context-link.ai/api/v1/context",
    params={"query": query},
    headers={"Authorization": api_key}
)

data = response.json()
print(data["message"])
```

### JavaScript example

```javascript
const axios = require('axios');

const apiKey = 'your-api-key-here';
const query = 'what is context link';

axios.get('https://context-link.ai/api/v1/context', {
    params: { query },
    headers: { 'Authorization': apiKey }
})
.then(response => {
    console.log(response.data.message);
})
.catch(error => {
    console.error('Error:', error.response.data);
});
```

### Ruby example

```ruby
require 'net/http'
require 'json'
require 'uri'

api_key = 'your-api-key-here'
query = 'what is context link'

uri = URI('https://context-link.ai/api/v1/context')
uri.query = URI.encode_www_form(query: query)

request = Net::HTTP::Get.new(uri)
request['Authorization'] = api_key

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
    http.request(request)
end

data = JSON.parse(response.body)
puts data['message']
```


## Response format

All successful responses return JSON with this structure:

```json
{
    "message": "The response content in Markdown format",
    "format": "markdown"
}
```

The `message` field contains the context-aware response generated from your connected knowledge sources. It's formatted as Markdown and may include:

- Headings and paragraphs
- Lists (bulleted and numbered)
- Code blocks
- Links to source material
- Emphasis and formatting

## Error responses

Errors follow this format:

```json
{
    "message": "Error description"
}
```

**Common errors:**

```json
// 400 Bad Request - Missing query
{
    "message": "A query is required"
}

// 401 Unauthorized - Missing API key
{
    "message": "API key required"
}

// 401 Unauthorized - Subscription required
{
    "message": "You need to be subscribed to access that page"
}

// 404 Not Found - Invalid API key
{
    "message": "Not found"
}
```

