> ## Documentation Index
> Fetch the complete documentation index at: https://axiom-mano-support-improvements.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Send data from Loki to Axiom

> Integrate Axiom in your existing Loki stack with minimal effort and without breaking any of your existing Loki workflows.

export const endpointName_0 = "Loki"

This page explains how to send data from Loki to Axiom.

## Prerequisites

* [Create an Axiom account](https://app.axiom.co/register).
* [Create a dataset in Axiom](/reference/datasets#create-dataset) where you send your data.
* [Create an API token in Axiom](/reference/tokens) with permissions to ingest data to the dataset you have created.

## Configure {endpointName_0} endpoint in Axiom

1. Click <Icon icon="gear" iconType="solid" /> **Settings > Endpoints**.
2. Click **New endpoint**.
3. Click **{endpointName_0}**.
4. Name the endpoint.
5. Select the dataset where you want to send data.
6. Copy the URL displayed for the newly created endpoint. This is the target URL where you send the data.

## Configure Loki

In Loki, specify the following environment variables:

* `host` or `url` is the target URL for the endpoint you have generated in Axiom by following the procedure above. For example, `https://opbizplsf8klnw.ingress.axiom.co`.
* Optional: Use `labels` or `tags` to specify labels or tags for your app.

The Axiom Loki endpoint accepts data through the [Loki HTTP push API](https://grafana.com/docs/loki/latest/reference/loki-http-api/#ingest-logs) (`/loki/api/v1/push`), so any client or agent that supports sending data to Loki can send data to Axiom with a configuration change.

## Migrate from an existing Loki deployment

If you already run Loki with agents like Promtail, Grafana Alloy, or Grafana Agent, you can redirect your log streams to Axiom by pointing these agents at the Axiom Loki endpoint URL instead of your Loki instance.

### Send logs from Promtail

In your Promtail configuration, replace the Loki URL in the `clients` section with the Axiom Loki endpoint URL:

```yaml theme={null}
clients:
  - url: $LOKI_ENDPOINT_URL/loki/api/v1/push
```

### Send logs from Grafana Alloy

In your Grafana Alloy configuration, use the `loki.write` component with the Axiom Loki endpoint URL:

```
loki.write "axiom" {
  endpoint {
    url = "$LOKI_ENDPOINT_URL/loki/api/v1/push"
  }
}
```

### Send logs using Vector

You can use [Vector](/send-data/vector) with the `loki` sink to forward logs to the Axiom Loki endpoint. This is useful if you want to use Vector as an intermediary to transform or route logs before sending them to Axiom.

```toml theme={null}
[sinks.axiom_loki]
type = "loki"
inputs = ["your_source"]
endpoint = "$LOKI_ENDPOINT_URL"
labels = { app = "my-app" }

[sinks.axiom_loki.encoding]
codec = "json"
```

<Note>
  For sending data to Axiom, the native [Axiom sink for Vector](/send-data/vector) is the recommended approach. Use the Loki sink for Vector only if you specifically need Loki protocol compatibility, for example during a gradual migration from Loki to Axiom.
</Note>

### Loki endpoint vs. Loki Multiplexer

The Axiom Loki endpoint (described on this page) and the [Loki Multiplexer](/send-data/loki-multiplexer) serve different purposes:

* **Loki endpoint**: Receives data directly from Loki-compatible clients and agents. Use this when you want to send logs to Axiom only.
* **Loki Multiplexer**: Acts as a proxy that accepts Loki HTTP API traffic and forwards it to both Axiom and other destinations. Use this when you want to send the same logs to Axiom and another Loki-compatible backend simultaneously, for example during a migration period.

## Examples

### Send logs from Loki using JavaScript

```js theme={null}
const { createLogger, transports, format, } = require("winston");
const LokiTransport = require("winston-loki");

let logger;

const initializeLogger = () => {
  if (logger) {
    return;
  }

  logger = createLogger({
    transports: [
      new LokiTransport({
        host: "$LOKI_ENDPOINT_URL",
        labels: { app: "axiom-loki-endpoint" },
        json: true,
        format: format.json(),
        replaceTimestamp: true,
        onConnectionError: (err) => console.error(err),
      }),
      new transports.Console({
        format: format.combine(format.simple(), format.colorize()),
      }),
    ],
  });
};

initializeLogger()
logger.info("Starting app...");
```

### Send logs from Loki using Python

```py theme={null}
import logging
import logging_loki

# Create a handler
handler = logging_loki.LokiHandler(
    url='$LOKI_ENDPOINT_URL',
    tags={'app': 'axiom-loki-py-endpoint'},
    version='1',
)

# Create a logger
logger = logging.getLogger('loki')

# Add the handler to the logger
logger.addHandler(handler)

# Log some messages
logger.info('Hello, world from Python!')
logger.warning('This is a warning')
logger.error('This is an error')
```
