@productminds/parseu-fetch
v0.1.1
Published
Plain TypeScript fetch client for the Parseu API
Readme
@productminds/parseu-fetch
A TypeScript client for the Parseu API built on
fetch, with no runtime dependencies. It works in Node.js 20 or later and in any
runtime with a global fetch.
Using Effect? Use the Effect-based client, @productminds/parseu, instead.
Install
npm install @productminds/parseu-fetchConfigure
import { createParseuClient } from "@productminds/parseu-fetch";
const parseu = createParseuClient({ apiKey: process.env.PARSEU_API_KEY! });Options: apiKey (required, sent as a bearer token), baseUrl (defaults to
https://api.parseu.ai), and fetch (defaults to the global fetch).
Upload and transcribe
import { openAsBlob } from "node:fs";
import { createParseuClient } from "@productminds/parseu-fetch";
const parseu = createParseuClient({ apiKey: process.env.PARSEU_API_KEY! });
const uploaded = await parseu.upload(await openAsBlob("./audio.wav"), {
filename: "audio.wav",
});
const result = await parseu.transcribeAndWait({
input: uploaded.uri,
language: "auto",
retention: "default",
});
if (result._tag === "Retained" && "text" in result.body) {
console.log(result.body.text);
}transcribeAndWait starts the job and polls until the result is final. To
control each step, call transcribe, getJob, and getResult yourself, or
call waitForResult(jobId) for an existing job. Both accept
{ intervalMs = 3000, timeoutMs = 600000, signal }.
upload accepts a Blob/File, or a FormData with a file entry. For large
files, call createPresignedUpload(), PUT the bytes to the returned
upload_url, then transcribe the returned uri.
Results
getResult returns an object tagged with _tag:
| _tag | Meaning | Fields |
| ---------- | ---------------------------------------------------- | ------------------------------- |
| Retained | Completed retained result | jobId, body |
| Zdr | Completed transient result requiring acknowledgement | jobId, body, resultSha256 |
| Pending | Result recovery is still in progress; poll again | jobId, body |
| Deleted | Result is deleted or expired | jobId, body |
waitForResult and transcribeAndWait never return Pending.
Zero data retention (ZDR)
For ZDR, submit a directly accessible HTTPS audio URL with retention: "none".
The result is transient: after you have stored it, acknowledge it to trigger
verified deletion. The client never acknowledges for you.
A ZDR result is available for a limited window after it is ready, currently 15
minutes, or until you acknowledge it. Fetch and acknowledge it promptly. The
window applies to the whole service and cannot be set per request. Results of
uploaded files (retention: "default") are retained for 30 days.
const result = await parseu.transcribeAndWait({
input: "https://your-storage.example.com/audio.wav",
language: "auto",
retention: "none",
});
if (result._tag === "Zdr") {
await saveSomewhereDurable(result.body);
await parseu.acknowledgeResult({
jobId: result.jobId,
resultSha256: result.resultSha256,
});
}Errors
ParseuError: the API returned a non-2xx response. It hasstatus,requestId(fromX-Request-Id; quote it when contacting support),tag, and the parsed errorbody. Documented error bodies are described by the exportedApiErrorBodytype, discriminated by_tag.ParseuJobError: a job waited on ended asfailedorcanceled.ParseuTimeoutError: the wait timed out. The job keeps running; resume withwaitForResult(error.jobId).ParseuNetworkError: the request could not be completed.ParseuAbortError: yourAbortSignalaborted the request or wait.ParseuResponseError: a successful response did not match the API contract.
import { ParseuError } from "@productminds/parseu-fetch";
try {
await parseu.getJob("job_123");
} catch (error) {
if (error instanceof ParseuError && error.status === 404) {
console.error("Unknown job", error.requestId);
} else {
throw error;
}
}Requests are never retried automatically. Every method also accepts
{ signal } as its last argument to cancel the request.
Methods
upload, createPresignedUpload, getFile, transcribe, getJob,
cancelJob, getResult, acknowledgeResult, waitForResult,
transcribeAndWait. Full API reference: https://api.parseu.ai/docs.
