can1357/oh-my-pi · error · Error

plik file response did not include an id

Error message

plik file response did not include an id

What it means

The Plik uploader parses the JSON response of the file-upload request through plikFile(), which only succeeds if the body contains an id field. Without an id the per-file download URL cannot be constructed, so the upload aborts with this error. It indicates the Plik server answered, but not with the expected file object.

Source

Thrown at packages/coding-agent/src/blob-broker/uploaders-self-hosted.ts:497

						removable,
					}),
				}),
				"plik",
			);
			const metadata = plikUpload(await metadataResponse.json());
			const uploadId = metadata.id;
			const uploadToken = metadata.uploadToken;
			const fileResponse = await expectOk(
				await requestFetch(endpoint(base, "file", uploadId), {
					method: "POST",
					headers: { "X-UploadToken": uploadToken },
					body: multipartFile(request),
				}),
				"plik",
			);
			const fileBody: unknown = await fileResponse.json();
			const file = plikFile(fileBody);
			if (!file) throw new Error("plik file response did not include an id");
			const fileId = file.id;
			const remoteName = file.name ?? filename;
			const downloadBase = metadata.downloadBase ?? base;
			const url = endpoint(downloadBase, "file", uploadId, fileId, remoteName);
			const deleteAction: RemoteDeleteAction = {
				method: "DELETE",
				url: endpoint(base, "upload", uploadId),
				headers: { "X-UploadToken": uploadToken },
			};
			const expiresAt = ttlSeconds !== undefined && ttlSeconds > 0 ? Date.now() + ttlSeconds * 1_000 : undefined;
			return publication("plik", request, url, {
				...(expiresAt === undefined ? {} : { expiresAt }),
				delete: deleteAction,
				remoteId: uploadId,
			});
		},
	};
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Verify the Plik server URL and that POST <base>/file returns a JSON object with an id (test with curl)
  2. Check for an error field in the response body (Plik may reject token/ttl settings with 200/error payloads)
  3. Confirm the server version matches the expected Plik API shape
  4. Check auth/proxy middleware isn't intercepting the upload request

Example fix

// before
const file = plikFile(fileBody);
if (!file) throw new Error("plik file response did not include an id");
// after: surface server error for diagnosis
const file = plikFile(fileBody);
if (!file) throw new Error(`plik file response did not include an id: ${JSON.stringify(fileBody).slice(0, 300)}`);
Defensive patterns

Strategy: type-guard

Validate before calling

const body = await fileResponse.json();
if (typeof body !== "object" || body === null || !("id" in body)) {
	throw new Error(`Plik returned unexpected payload: ${JSON.stringify(body).slice(0, 200)}`);
}

Type guard

function isPlikFile(v: unknown): v is { id: string; name?: string } {
	return typeof v === "object" && v !== null && typeof (v as { id?: unknown }).id === "string";
}

Try / catch

try {
	await uploader.upload(req);
} catch (err) {
	if (err instanceof Error && err.message.includes("plik file response")) {
		// log raw response body; check Plik server URL and error field
	}
	throw err;
}

Prevention

When it happens

Trigger: POST of the multipart upload to the Plik server returns 2xx but the JSON body either is not a file object (e.g. an error object, a null, or a missing id) — typically because the server rejected the upload token/ttl settings but still returned 200, or because the endpoint URL points at a non-Plik service.

Common situations: Pointing the plik base URL at a wrong path or a compatible-but-different service; a Plik server with upload tokens required returning {error: ...}; proxy or auth middleware returning an HTML/JSON page that is not a Plik file response.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/4f5064369e34ffec. Report an issue: GitHub.