Repository navigation
Expand file tree
/
Copy pathcheck-plan.mjs
More file actions
44 lines (38 loc) · 2 KB
/
Copy pathcheck-plan.mjs
File metadata and controls
44 lines (38 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Free check before any Instagram job: is Instagram open to this key, and how many credits are left?
//
// Cost: none. Reads GET /v1/capabilities and GET /v1/usage only.
// Run: TRANSCRIPTDOCK_API_KEY=td_live_... node check-plan.mjs
// Node 18 or newer. No dependencies.
const API = "https://www.transcriptdock.com"; // always www: the apex domain redirects
const KEY = process.env.TRANSCRIPTDOCK_API_KEY;
if (!KEY) {
console.error("Set TRANSCRIPTDOCK_API_KEY to your td_live_ key.");
process.exit(1);
}
async function get(path) {
const res = await fetch(API + path, { headers: { Authorization: `Bearer ${KEY}` }, redirect: "error" });
if (!res.ok) {
const data = await res.json().catch(() => ({}));
throw new Error(`${res.status} ${data.error?.code ?? "HTTP_ERROR"}: ${data.error?.message ?? res.statusText}`);
}
return res.json();
}
// With a key, capabilities answer for this workspace's plan.
const capabilities = await get("/v1/capabilities");
const usage = await get("/v1/usage");
const instagram = capabilities.instagram;
console.log(`Plan: ${usage.plan}`);
console.log(`Credits left: ${usage.credits_remaining} (held by running jobs: ${usage.credits_reserved})`);
console.log(`Instagram captions_only: ${instagram.captions_only} (never supported: there is no caption path)`);
console.log(`Instagram auto: ${instagram.auto}, transcribe: ${instagram.transcribe}`);
console.log(
`AI transcription: ${capabilities.transcribe_credits_per_minute} credits per started minute,` +
` ${capabilities.minimum_billable_seconds} second minimum`,
);
if (!instagram.auto && !instagram.transcribe) {
console.log("\nInstagram jobs are not open to this key. AI transcription needs a paid plan: https://www.transcriptdock.com/pricing");
process.exit(1);
}
// How long a Reel can these credits cover? (2 credits per started minute)
const minutes = Math.floor(usage.credits_remaining / capabilities.transcribe_credits_per_minute);
console.log(`\nReady. Your balance covers about ${minutes} minute(s) of Instagram audio.`);