# xAI Integration via LowCodeAPI

## Overview

xAI API for chat completions and AI model interactions

## Base Endpoint

```
https://api.lowcodeapi.com/xai/
```

## Authentication

LowCodeAPI handles authentication automatically. You only need to:

1. **Sign up** at [xAI](https://x.ai)
2. **Get your credentials** from [credential page](https://console.x.ai)
3. **Connect your account** in LowCodeAPI dashboard
4. **Use your `api_token`** in all requests

**Auth Type**: TOKEN

## API Categories

- **API Key** - 1 endpoints
- **Chat** - 2 endpoints
- **Completions** - 2 endpoints
- **Files** - 9 endpoints
- **Images** - 1 endpoints
- **Message** - 1 endpoints
- **Models** - 6 endpoints
- **Responses** - 3 endpoints
- **Text** - 1 endpoints

## Common Endpoints

### Category: API Key

#### Get API Key

**Method**: `GET` | **LowCodeAPI Path**: `/v1/api-key`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/api-key?api_token={api_token}
```

**Description**: Get information about the current API key

---

### Category: Chat

#### Create Chat Completion

**Method**: `POST` | **LowCodeAPI Path**: `/v1/chat/completions`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/chat/completions?api_token={api_token}
```

**Description**: Creates a model response for the given chat conversation

**Request Body**:
```json
{
  "model": "<string>",
  "messages": "<array>"
}
```

---

#### Get Deferred Chat Completion

**Method**: `GET` | **LowCodeAPI Path**: `/v1/chat/deferred-completion/request_id`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/chat/deferred-completion/request_id?request_id={request_id}&api_token={api_token}
```

**Description**: Get the result of a deferred chat completion request

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`request_id` | string | Yes | The ID of the deferred completion request |

---

### Category: Completions

#### Create Completion

**Method**: `POST` | **LowCodeAPI Path**: `/v1/completions`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/completions?api_token={api_token}
```

**Description**: Creates a completion for the provided prompt and parameters (Legacy endpoint)

**Request Body**:
```json
{
  "model": "<string>",
  "prompt": "<string>"
}
```

---

#### Create Completion (Anthropic Compatible)

**Method**: `POST` | **LowCodeAPI Path**: `/v1/complete`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/complete?api_token={api_token}
```

**Description**: Creates a completion (Anthropic compatible legacy endpoint)

**Request Body**:
```json
{
  "model": "<string>",
  "prompt": "<string>",
  "max_tokens_to_sample": "<number>"
}
```

---

### Category: Files

#### List Files

**Method**: `GET` | **LowCodeAPI Path**: `/v1/files`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/files?api_token={api_token}
```

**Description**: Returns a list of files that belong to the user's organization

---

#### Get File Metadata

**Method**: `GET` | **LowCodeAPI Path**: `/v1/files/file_id`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/files/file_id?file_id={file_id}&api_token={api_token}
```

**Description**: Returns information about a specific file

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`file_id` | string | Yes | The ID of the file to use for this request |

---

#### Delete File

**Method**: `DELETE` | **LowCodeAPI Path**: `/v1/files/file_id`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/files/file_id?file_id={file_id}&api_token={api_token}
```

**Description**: Delete a file

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`file_id` | string | Yes | The ID of the file to delete |

---

#### Download File

**Method**: `GET` | **LowCodeAPI Path**: `/v1/files/file_id/download`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/files/file_id/download?file_id={file_id}&api_token={api_token}
```

**Description**: Download a file

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`file_id` | string | Yes | The ID of the file to download |

---

#### Update File

**Method**: `PATCH` | **LowCodeAPI Path**: `/v1/files/file_id`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/files/file_id?file_id={file_id}&api_token={api_token}
```

**Description**: Update a file's metadata or content

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`file_id` | string | Yes | The ID of the file to update |

**Request Body**:
```json
{
  "key": "value"
}
```

---

#### Initialize File Upload

**Method**: `POST` | **LowCodeAPI Path**: `/v1/files/upload`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/files/upload?api_token={api_token}
```

**Description**: Initialize a file upload session

**Request Body**:
```json
{
  "file_name": "<string>",
  "file_size": "<number>"
}
```

---

#### Upload File Chunk

**Method**: `POST` | **LowCodeAPI Path**: `/v1/files/upload/upload_id/chunks`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/files/upload/upload_id/chunks?upload_id={upload_id}&api_token={api_token}
```

**Description**: Upload a file in chunks

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`upload_id` | string | Yes | The ID of the upload session |

**Request Body**:
```json
{
  "chunk": "<file>",
  "chunk_number": "<number>"
}
```

---

#### Batch Upload Files

**Method**: `POST` | **LowCodeAPI Path**: `/v1/files/batch`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/files/batch?api_token={api_token}
```

**Description**: Batch upload files

**Request Body**:
```json
{
  "files": "<array>"
}
```

---

#### Complete Batch Upload

**Method**: `POST` | **LowCodeAPI Path**: `/v1/files/batch/batch_id/complete`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/files/batch/batch_id/complete?batch_id={batch_id}&api_token={api_token}
```

**Description**: Complete a batch upload file session and process uploaded files

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`batch_id` | string | Yes | The ID of the batch upload session |

---

### Category: Images

#### Create Image Generation

**Method**: `POST` | **LowCodeAPI Path**: `/v1/images/generations`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/images/generations?api_token={api_token}
```

**Description**: Creates an image generation request

**Request Body**:
```json
{
  "model": "<string>",
  "prompt": "<string>"
}
```

---

### Category: Message

#### Create a Message

**Method**: `POST` | **LowCodeAPI Path**: `/v1/messages`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/messages?api_token={api_token}
```

**Description**: Create a message (Anthropic compatible endpoint)

**Request Body**:
```json
{
  "model": "<string>",
  "messages": "<array>",
  "max_tokens": "<number>"
}
```

---

### Category: Models

#### List Models

**Method**: `GET` | **LowCodeAPI Path**: `/v1/models`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/models?api_token={api_token}
```

**Description**: Lists the currently available models, and provides basic information about each one such as the owner and availability

---

#### Retrieve Model

**Method**: `GET` | **LowCodeAPI Path**: `/v1/models/model_id`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/models/model_id?model_id={model_id}&api_token={api_token}
```

**Description**: Retrieves a model instance, providing basic information about the model such as the owner and permissioning

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`model_id` | string | Yes | The ID of the model to use for this request |

---

#### List Language Models

**Method**: `GET` | **LowCodeAPI Path**: `/v1/language-models`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/language-models?api_token={api_token}
```

**Description**: Lists the currently available language models

---

#### Get Language Model

**Method**: `GET` | **LowCodeAPI Path**: `/v1/language-models/model_id`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/language-models/model_id?model_id={model_id}&api_token={api_token}
```

**Description**: Retrieves a specific language model by ID

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`model_id` | string | Yes | The ID of the language model |

---

#### List Image Generation Models

**Method**: `GET` | **LowCodeAPI Path**: `/v1/image-generation-models`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/image-generation-models?api_token={api_token}
```

**Description**: Lists the currently available image generation models

---

#### Get Image Generation Model

**Method**: `GET` | **LowCodeAPI Path**: `/v1/image-generation-models/model_id`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/image-generation-models/model_id?model_id={model_id}&api_token={api_token}
```

**Description**: Retrieves a specific image generation model by ID

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`model_id` | string | Yes | The ID of the image generation model |

---

### Category: Responses

#### Create New Response

**Method**: `POST` | **LowCodeAPI Path**: `/v1/responses`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/responses?api_token={api_token}
```

**Description**: Create a new response

**Request Body**:
```json
{
  "model": "<string>",
  "messages": "<array>"
}
```

---

#### Retrieve Previous Response

**Method**: `GET` | **LowCodeAPI Path**: `/v1/responses/response_id`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/responses/response_id?response_id={response_id}&api_token={api_token}
```

**Description**: Retrieve a previous response by ID

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`response_id` | string | Yes | The ID of the response to retrieve |

---

#### Delete Previous Response

**Method**: `DELETE` | **LowCodeAPI Path**: `/v1/responses/response_id`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/responses/response_id?response_id={response_id}&api_token={api_token}
```

**Description**: Delete a previous response by ID

**Path Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
|`response_id` | string | Yes | The ID of the response to delete |

---

### Category: Text

#### Tokenize Text

**Method**: `POST` | **LowCodeAPI Path**: `/v1/tokenize-text`

**Full URL**:
```
https://api.lowcodeapi.com/xai/v1/tokenize-text?api_token={api_token}
```

**Description**: Tokenize text using a specified model

**Request Body**:
```json
{
  "model": "<string>",
  "text": "<string>"
}
```

---

## Complete Endpoint Reference

For a complete list of all 26 endpoints, refer to:
- **OpenAPI Definition**: `https://backend.lowcodeapi.com/xai/definition`
- **Official Provider Documentation**: https://docs.x.ai/docs/api-reference