0

Logs Query

by
Published Oct 17, 2025

Query inference logs. * Without timestamps (from/to) returns last `limit` messages (in last month). * With `from` only, returns first `limit` messages after `from` (inclusive). * With `to` only, returns last `limit` messages before `to` (inclusive). * With both `from` and `to`, return the first `limit` messages after `from`, but not later than `to`. * `from` and `to` should be no more than a month apart.

Script deep_infra Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Deepinfra = {
3
  token: string;
4
};
5
/**
6
 * Logs Query
7
 * Query inference logs.
8
 * Without timestamps (from/to) returns last `limit` messages (in last month).
9
 * With `from` only, returns first `limit` messages after `from` (inclusive).
10
 * With `to` only, returns last `limit` messages before `to` (inclusive).
11
 * With both `from` and `to`, return the first `limit` messages after `from`, but not later than `to`.
12
 * `from` and `to` should be no more than a month apart.
13
 */
14
export async function main(
15
  auth: Deepinfra,
16
  deploy_id: string | undefined,
17
  from: string | undefined,
18
  to: string | undefined,
19
  limit: string | undefined,
20
) {
21
  const url = new URL(`https://api.deepinfra.com/v1/logs/query`);
22
  for (const [k, v] of [
23
    ["deploy_id", deploy_id],
24
    ["from", from],
25
    ["to", to],
26
    ["limit", limit],
27
  ]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45