HTTP API to Grafana Cloud Loki

I have an Grafana Loki HTTP API working right now.

const url = new URL('http://not-sharing-this:3100/loki/api/v1/query_range');
url.searchParams.set('query', '{job="bob_job", branch="master"}');
url.searchParams.set('limit', '500');

fetch(url.toString(), {
    method: 'POST',
    .then((response) => response.json())
    .then((obj) => {

I need to transition to use Grafana Cloud Loki. I’m not finding the resources I need, maybe I don’t know the keywords to google, and I’m really at a loss.

Hi @taylormo !

If you wish to push logs to Grafana Cloud using the Loki HTTP API, update the URL in your example to your hosted Loki instance URL and add authentication using basic_auth.

In your account portal, click on the “details” button next to Loki to find the Loki username (which is the instance ID) and generate an API Key or Access Policy token for auth.

The Loki HTTP API endpoint for your Grafana Cloud’s instance should look something like https://$

For example, my endpoint in us-central1 is:

Note that in general, we recommend using the official client options to send logs to Grafana Cloud since the Loki HTTP API is not considered stable.

1 Like

@Melody Can you extrapolate on what you mean by region?

const tmp = new URL('https://<this>');
tmp.searchParams.set('query', '{job="bobjob"}');
fetch(tmp.toString(), {
    method: 'POST',
    headers: {
        'Authorization': 'Basic ' + btoa(user + ":" + apikey)
    .then((response) => console.log(response));

This yields the error:

Access to fetch at 'https://<this>' from origin 'http://<wherever>.net' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.