0

List Datasets

by
Published Apr 8, 2025

List datasets that have been created.

Script cohere Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Cohere = {
3
  apiKey: string;
4
};
5
/**
6
 * List Datasets
7
 * List datasets that have been created.
8
 */
9
export async function main(
10
  auth: Cohere,
11
  datasetType: string | undefined,
12
  before: string | undefined,
13
  after: string | undefined,
14
  limit: string | undefined,
15
  offset: string | undefined,
16
  validationStatus:
17
    | "unknown"
18
    | "queued"
19
    | "processing"
20
    | "failed"
21
    | "validated"
22
    | "skipped"
23
    | undefined,
24
) {
25
  const url = new URL(`https://api.cohere.com/v1/datasets`);
26
  for (const [k, v] of [
27
    ["datasetType", datasetType],
28
    ["before", before],
29
    ["after", after],
30
    ["limit", limit],
31
    ["offset", offset],
32
    ["validationStatus", validationStatus],
33
  ]) {
34
    if (v !== undefined && v !== "" && k !== undefined) {
35
      url.searchParams.append(k, v);
36
    }
37
  }
38
  const response = await fetch(url, {
39
    method: "GET",
40
    headers: {
41
      Authorization: "Bearer " + auth.apiKey,
42
    },
43
    body: undefined,
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51