# Network Intel API

### Overview

The Datagram Network Intel API provides access to language models through a chat completions endpoint. This API allows you to interact with various AI models in a conversational format.

**Base URL:** `https://intel.api.datagram.network`

### Authentication

All API requests require authentication using an API key passed in the Authorization header.

**Authorization:**`Bearer YOUR_API_KEY`

### Chat Completions

**Endpoint**

```
POST /api/v1/chat/completions
```

**URL**

```
https://intel.api.datagram.network/api/v1/chat/completions
```

Creates a chat completion response for the given conversation.

**Headers**

| Header                 | Required | Description                         | Example                           |
| ---------------------- | -------- | ----------------------------------- | --------------------------------- |
| **Authorization**      | Yes      | Bearer token for API authentication | `Bearer sk_live_abc123...xyz456`  |
| **Content-Type**       | Yes      | Must be application/json            | `application/json; charset=utf-8` |
| **sec-ch-ua-platform** | No       | Client platform information         | `"Windows"`                       |

**Request Body**

| Parameter    | Type    | Required | Description                                              | Example                                                      |
| ------------ | ------- | -------- | -------------------------------------------------------- | ------------------------------------------------------------ |
| **model**    | string  | Yes      | ID of the model to use (e.g., "llama3.2:1b")             | `"llama3.2:1b"`                                              |
| **messages** | array   | Yes      | Array of message objects representing the conversation   | `[{"role": "user", "content": "Explain quantum computing"}]` |
| **stream**   | boolean | No       | Whether to stream back partial progress (default: false) | true                                                         |

**Message Object**

| Parameter   | Type   | Required | Description                                              | Example                                           |
| ----------- | ------ | -------- | -------------------------------------------------------- | ------------------------------------------------- |
| **role**    | string | Yes      | The role of the message author (system, user, assistant) | `"user"`                                          |
| **content** | array  | Yes      | Array of content objects containing the message text     | `[{"type": "text", "text": "Explain AI safety"}]` |

**Content Object**

<table><thead><tr><th width="97">Parameter</th><th width="90">Type</th><th>Required</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><strong>type</strong></td><td>string</td><td>Yes</td><td>Type of content (e.g., "text")</td><td><code>"text"</code></td></tr><tr><td><strong>text</strong></td><td>string</td><td>Yes</td><td>The actual text content</td><td><code>"Explain quantum entanglement"</code></td></tr></tbody></table>

### Examples

#### Basic Chat Completion

```
curl 'https://intel.api.datagram.network/api/v1/chat/completions' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "model": "llama3.2:1b",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What is the capital of France?"
          }
        ]
      }
    ],
    "stream": false
  }'
```

#### Chat with System Message

```
curl 'https://intel.api.datagram.network/api/v1/chat/completions' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "model": "llama3.2:1b",
    "messages": [
      {
        "role": "system",
        "content": [
          {
            "type": "text",
            "text": "You are a helpful assistant that speaks like a pirate."
          }
        ]
      },
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Tell me about the weather"
          }
        ]
      }
    ],
    "stream": false
  }'
```

#### Streaming Response

```
curl 'https://intel.api.datagram.network/api/v1/chat/completions' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "model": "llama3.2:1b",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Write a short story about a robot"
          }
        ]
      }
    ],
    "stream": true
  }'
```

#### Multi-turn Conversation

```
curl 'https://intel.api.datagram.network/api/v1/chat/completions' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "model": "llama3.2:1b",
    "messages": [
      {
        "role": "system",
        "content": [
          {
            "type": "text",
            "text": "You are a helpful coding assistant."
          }
        ]
      },
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "How do I create a Python function?"
          }
        ]
      },
      {
        "role": "assistant",
        "content": [
          {
            "type": "text",
            "text": "To create a Python function, use the def keyword followed by the function name and parameters in parentheses."
          }
        ]
      },
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Can you show me an example?"
          }
        ]
      }
    ],
    "stream": false
  }'
```

### Response Format

#### Non-streaming Response

```
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "llama3.2:1b",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21
  }
}
```

#### Streaming Response

When stream: true is set, the server sends data in Server-Sent Events (SSE) format:

```
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"llama3.2:1b","choices":[{"index":0,"delta":{"role":"assistant","content":"The"},"finish_reason":null}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"llama3.2:1b","choices":[{"index":0,"delta":{"content":" capital"},"finish_reason":null}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"llama3.2:1b","choices":[{"index":0,"delta":{"content":" of"},"finish_reason":null}]}

data: [DONE]
```

### Available Models

Based on the example, the following model is available:

* `llama3.2:1b` - Llama 3.2 1B parameter model

Note: Contact the API provider for a complete list of available models.

### Error Handling

The API returns standard HTTP status codes:

* `200` - Success
* `400` - Bad Request (invalid parameters)
* `401` - Unauthorized (invalid API key)
* `429` - Rate Limit Exceeded
* `500` - Internal Server Error

#### Example Error Response

```
{
  "error": {
    "message": "Invalid API key provided",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}
```

### Rate Limits

Rate limits may apply depending on your API plan. Check the response headers for rate limit info:

* `X-RateLimit-Limit` - Max requests per time window
* `X-RateLimit-Remaining` - Remaining requests in current window
* `X-RateLimit-Reset` - Time when limit resets

### Best Practices

1. **Include System Messages**: Use them to define assistant behavior.
2. **Handle Streaming**: Implement proper error handling.
3. **Token Management**: Monitor usage.
4. **Conversation Context:** Maintain full message history.
5. **Error Handling:** Gracefully handle failures.


---

# 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://doc.datagram.network/apis/api-reference/network-intel-api.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.
