Developer infrastructure platform
Cap Infra is a developer-facing video platform. It lets a developer create an app, send video through an API or the console, receive processed playback links and webhook events, request transcripts, and pay for stored media, delivery, and speech use with app credits. It extends the broader web product through focused API and media workflows; see also web application routes, web API and domain services, and infrastructure MCP tooling.
Product boundary
Cap Infra gives an external product a small media service boundary. An app owns its videos, transcripts, API keys, credit account, webhook endpoints, and playback identity, while the platform manages media processing, object storage, usage records, delivery measurement, and cleanup.
| Product concern | System responsibility |
|---|---|
| App access | Provide an app identity, environment, keys, settings, and embed controls. |
| Video | Accept a source file, process it, and expose playback and share links. |
| Audio | Turn an upload or public media URL into a searchable transcript. |
| Delivery | Measure viewer playback so delivery use can be shown and billed. |
| Credits | Admit work, record use, and report the account ledger. |
| Operations | Remove abandoned, failed, and deleted media over time. |
App model
An Infra app is the unit of ownership and billing. The console lets an authenticated owner create an app for a development or production environment, change its name or environment, rotate its public and secret keys, and manage allowed embed sites and settings through the app shell in apps/…/layout.tsx.
The secret key identifies server-side API calls. The public key is not accepted by the secret API, so browser upload access uses a short-lived upload token issued by a trusted server. App creation also creates the credit account that controls access to billable work in apps/…/create-app.ts.
References: apps/…/layout.tsx• L5-31 apps/…/create-app.ts• L24-91 apps/…/regenerate-keys.ts• L18-82 apps/…/app-settings-client.tsx• L68-121
Console workspace
The console is the operator view for one Infra app. Its overview shows credit balance, stored minutes, video count, storage charges, recent video activity, and setup paths for the API and an agent. Its child views cover videos, a single video, keys, settings, billing, usage, webhooks, and audio transcripts in apps/…/page.tsx and apps/…/shell.tsx.
The console can upload one or more videos without a separate customer integration. It shows progress, keeps uploads moving while the user changes pages in the same app, and asks before a navigation would cancel work. It also exposes playback links and processing state so an engineer can check the same resource that an API client uses. Opening a video can restart work that stalled, which gives console-only users a recovery path in apps/…/uploads.tsx and apps/…/infra-data.ts.
References: apps/…/page.tsx• L50-133 apps/…/page.tsx• L18-67 apps/…/shell.tsx• L61-77 apps/…/uploads.tsx• L516-674 apps/…/infra-data.ts• L224-254
API lifecycle
The API lifecycle moves from app setup to authenticated resource work. The secret API groups app, video, upload, transcript, usage, transaction, and webhook operations under /api/developer/v1; the SDK surface accepts a scoped upload token for browser or client-side multipart transfer in apps/…/route.ts.
Authentication surfaces
Secret-key requests act on one app and can list or change its resources. Upload-token requests act on one video only and cannot be reused for another video. This split keeps the app secret on a server while still allowing a client to send large files directly to storage.
The console uses the signed-in owner session rather than an app secret. Its upload API checks that the owner controls the selected app before it creates or changes an upload in apps/…/route.ts.
References: apps/…/route.ts• L15-31 apps/…/route.ts• L12-27 apps/…/route.ts• L173-216
Video API
The video API returns app-scoped video records and status records. A client can create an upload, list or inspect videos, filter by its own external user ID, delete a video, and ask for status; pagination keeps large app histories bounded in apps/…/videos.ts.
The API reports the business state rather than the media server's internal job state. A video is normally uploading, processing, ready, or errored, and a ready response includes the available HLS, MP4, poster, share, and embed links. A repeated read may also trigger recovery for stale processing in apps/…/videos.ts and apps/…/developer-video-api.ts.
References: apps/…/videos.ts• L73-173 apps/…/developer-video-api.ts• L17-55 apps/…/developer-video-api.ts• L104-149
Webhook notifications
Webhook notifications give an app a server-side signal when video work reaches a customer-visible result. An owner can add a public HTTPS endpoint, choose the video events it receives, test delivery, disable or enable the endpoint, and rotate its signing secret in apps/…/webhooks-client.tsx.
The endpoint secret is shown only when it is created or rotated. Repeated delivery failures can turn an endpoint off, so the console shows the last result and failure streak before the owner fixes the endpoint and turns it on again. The receiver uses the secret to check the signed request rather than trusting the endpoint URL alone.
References: apps/…/page.tsx• L15-49 apps/…/webhooks-client.tsx• L150-199 apps/…/webhooks-client.tsx• L454-560
Upload lifecycle
Video upload separates resource creation from file transfer. The API first creates a video and returns its playback identity and an upload token. The client then initiates a multipart upload, requests signed part URLs, sends the parts to object storage, and completes or aborts the upload through the token-bound SDK surface.
Completion checks the stored parts and measured size before it records the video. It admits the video against the app's credit and storage standing, then starts processing. Idempotency and completion claims make a repeated request settle on one recorded upload instead of charging or processing it twice in apps/…/infra-video-upload.ts.
The flow below shows how control moves from the app API to direct storage and then back to processing.
flowchart LR
A[Create video] --> B[Issue upload token]
B --> C[Initiate multipart upload]
C --> D[Presign parts]
D --> E[Upload parts to storage]
E --> F[Complete upload]
F --> G{Credit and size checks}
G -->|accepted| H[Start media processing]
G -->|refused| I[Return error and discard upload]
References: apps/…/uploads.ts• L49-131 apps/…/upload.ts• L51-159 apps/…/infra-video-upload.ts• L323-370 apps/…/infra-video-upload.ts• L544-705
Video processing and playback
Video processing turns one uploaded source into outputs that are useful to both a player and a download client. The platform probes the source, chooses a resolution ladder up to the app's allowed tier, asks the media server for MP4 and adaptive streaming outputs, and records only outputs that pass storage and playlist checks.
Processing states
Processing uses separate MP4 and HLS work parts. A video can become ready when one usable output exists, so MP4 playback can remain available while adaptive streaming is retried. The workflow watches quiet jobs, retries lost jobs, limits failed attempts, and marks a video errored when no output can be completed in apps/…/process-developer-video.ts.
Media-server progress is accepted only for the current video part and attempt. This prevents an old job or a late callback from replacing a newer result in apps/…/developer-video-processing.ts.
References: apps/…/process-developer-video.ts• L51-118 apps/…/developer-video-state.ts• L70-84 apps/…/developer-video-processing.ts• L937-1045 apps/…/route.ts• L123-132
Playback delivery
Playback uses a stable playback ID instead of exposing storage keys. The playback endpoint checks that the app and video are live, pauses delivery when the app is paused for unpaid storage, and redirects media files to signed storage URLs. An app can also limit embedded playback to a set of allowed sites; share links, streams, and downloads remain open when that list is used.
HLS playlists are served with the links needed by a player. MP4 and poster files are served as direct playback targets. Share and embed pages use the same playback ID, which lets a customer place a processed video on its own site without exposing the source object. The console can generate embed code with controls, muted autoplay, captions, a quality menu, and an accent color in apps/…/embed-options.tsx.
References: apps/…/route.ts• L7-27 apps/…/developer-video-playback.ts• L251-331 apps/…/developer-video-api.ts• L37-55 apps/…/embed-options.tsx• L18-117 apps/…/domains-section.tsx• L38-42
Transcription lifecycle
The transcription product accepts either a direct file upload or a public media URL. It validates the source, extracts audio, sends that audio to speech recognition, stores a result with text and time marks, and exposes progress and errors through the same developer API.
Transcript states
A transcript moves through uploading, queued, processing, complete, or error. Upload-based requests need an explicit start after the file reaches storage; URL-based requests can queue work at creation time. The API supports idempotency so a retry can return the same transcript rather than create a second job in apps/…/transcripts.ts.
The workflow checks source reachability and media type before it extracts audio. It enforces size and duration limits, holds enough credits while the source and audio are measured, and settles the final charge after speech work completes. A result contains text, language, word time marks, and grouped segments in apps/…/developer-transcribe.ts.
References: apps/…/transcripts.ts• L65-122 apps/…/developer-transcript-store.ts• L431-542 apps/…/developer-transcribe.ts• L187-271 apps/…/developer-transcripts.ts• L20-60
Transcript access
The API returns a transcript summary for lists and a full text result for an individual transcript. Clients can request words or segments when they need timed data, while the console presents the same work as an audio workspace with status, duration, cost, and no-speech results in apps/…/page.tsx.
Deleting a transcript hides its row and removes its source, extracted audio, and result objects. A scheduled cleanup also expires uploads or jobs that remain stale and can redispatch queued work that never started in apps/…/developer-transcript-store.ts.
References: apps/…/transcripts.ts• L170-239 apps/…/page.tsx• L10-30 apps/…/developer-transcript-store.ts• L861-974
Credits and metering
Credits are the shared payment unit for an Infra app. The platform uses them to decide whether new work can start and records additions and usage debits in an app ledger, while the console and API expose the balance in customer-readable form.
Credit standing
The platform combines available credit with the latest storage charge to derive an app standing: active, grace, or paused. A short balance starts a grace period; if the owed amount is not restored, new uploads are blocked and playback returns a paused response. A disputed payment pauses the app directly in apps/…/infra-standing.ts.
Uploads also need enough credit to cover an admission period for the app's expected stored media. This check happens before the upload starts and again after the real file duration and dimensions are known, so a client cannot use an under-reported upload to bypass the account gate in apps/…/infra-standing.ts and apps/…/developer-video-processing.ts.
References: apps/…/infra-standing.ts• L18-49 apps/…/infra-standing.ts• L92-111 apps/…/infra-standing.ts• L297-358 apps/…/developer-video-processing.ts• L337-397
Usage metering
Video storage is metered by stored minutes and resolution tier. Upload and encoding are free; a ready video receives its first month of storage and then incurs daily storage charges. Delivery is metered by the minutes viewers watch at each delivery tier. Speech is metered by measured audio seconds and charged when a transcript settles.
The usage API brings these measures together with the balance, standing, upload admission result, and current rates. The console adds daily storage snapshots, monthly totals, transcript usage, and delivered minutes so a customer can connect the ledger to the media it stores and the playback it serves. Recent delivery data can still change while the current and prior day settle in apps/…/usage.ts and apps/…/page.tsx.
References: apps/…/developer-pricing.ts• L61-160 apps/…/infra-storage-billing.ts• L84-248 apps/…/developer-transcript-billing.ts• L256-374 apps/…/usage.ts• L27-73 apps/…/page.tsx• L75-151 apps/…/delivered-minutes.tsx• L24-90
Credit purchases
The billing view lets an app owner add credits, view or export the transaction ledger, and enable automatic top-up. A saved card can add a chosen amount when the balance falls below a chosen threshold, subject to per-day and per-app limits; a declined charge turns the feature off. Credit additions are tied to a payment reference so a repeated payment callback does not add the same funds twice; usage debits keep a reference to the video or transcript that consumed them in apps/…/developer-credits.ts and apps/…/auto-top-up.tsx.
The app can read the same ledger through the transactions API. This gives customer systems a durable record of top-ups, video or speech use, storage charges, and adjustments without requiring access to the console in apps/…/transactions.ts.
References: apps/…/page.tsx• L32-87 apps/…/billing-view.tsx• L208-268 apps/…/auto-top-up.tsx• L134-150 apps/…/developer-credits.ts• L13-92 apps/…/developer-credits.ts• L113-200 apps/…/transactions.ts• L15-31
Storage and cleanup
Object storage holds source uploads, encoded video outputs, posters, transcript sources, extracted audio, and transcript results. Database rows remain the system's record of ownership and state, while storage cleanup follows those rows and delayed write windows.
Storage accounting
Storage usage groups an app's live videos by resolution tier and duration. The billing sweep records a daily snapshot before it charges the account, which lets the console show what was stored on each billed day even after the current collection changes.
The platform keeps storage and business state separate. A deleted or failed video may still have objects for a short period, but it is no longer treated as active customer media; a later purge removes those objects and records that the files are gone in apps/…/infra-storage.ts and apps/…/developer-video-purge.ts. The console presents stored size as context only because storage billing uses video minutes rather than bytes in apps/…/video-client.tsx.
References: apps/…/infra-storage.ts• L77-161 apps/…/infra-storage-billing.ts• L56-82 apps/…/developer-video-purge.ts• L60-155 apps/…/video-client.tsx• L343-351
Scheduled operations
Scheduled routes keep the platform bounded without making customer requests do all cleanup. The storage sweep bills accounts and runs due top-ups; upload cleanup aborts old multipart uploads and removes unrecorded files; video purge removes deleted or old failed outputs; transcript cleanup expires abandoned jobs and stale upload objects. Delivery settlement also turns viewer playback records into usage totals after its measurement window.
Each operation is repeatable and bounded. It uses continuation work or later runs for large backlogs, and it delays final video deletion long enough for media-server jobs with valid signed write links to finish. Cron routes require the shared secret before they can change storage, delivery, or billing state.
References: apps/…/route.ts• L313-413 apps/…/route.ts• L47-211 apps/…/route.ts• L28-67 apps/…/route.ts• L30-68
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the video status serializer, console view, API response, webhook event, and playback URL rules aligned. A new output or state can otherwise appear in one surface but not another.
- Keep upload-token limits, multipart completion checks, and direct-storage cleanup aligned. A changed token rule can strand parts or permit a token to finish the wrong video.
- Keep admission, measured media metadata, daily storage billing, delivery settlement, and standing transitions aligned. A change in duration, resolution, or playback can alter both acceptance and later pause or charge behavior.
- Keep transcript holds, final speech charges, result storage, and usage totals aligned. A retry must not create a second charge or leave a hold after an error.
- Keep webhook event names, endpoint limits, one-time secret display, signature checks, and failure disable rules aligned. A receiver can silently miss events if any one of these contracts changes alone.
- Keep deletion timestamps and purge grace windows aligned with signed media-server write URLs. Removing objects too early can lose a late encode; removing them too late can keep deleted media playable.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| App has no usable credit or has an unpaid storage charge | New uploads or transcripts are refused. Playback can be paused after the grace period. | Admission checks and active/grace/paused standing rules. |
| Upload parts are missing, changed, too small, or over the limit | Completion fails and the client must upload again. | Storage validates part numbers, ETags, size, and the upload token's video binding. |
| Media server cannot probe or encode the source | The video retries when the fault may clear, or ends as errored with a customer-safe reason. | Probe classification, bounded retries, job checks, and a processing deadline. |
| Source URL is private, unreachable, unsupported, or too large | The transcript enters error and its reserved credits are released. | Public URL checks, source sniffing, size and duration limits, and workflow failure settlement. |
| Webhook endpoint returns repeated failures | Cap disables the endpoint and later video events stop reaching the app. | Delivery status, failure streaks, test delivery, and explicit re-enable controls. |
| A cleanup run stops during a large backlog or object delete | Some rows or objects remain for a later run. | Bounded batches, cursors or continuation calls, delayed purge markers, and repeat-safe charges. |
Key files
| File | Why to read it |
|---|---|
| apps/…/page.tsx | Shows the main customer view and the product's core app, video, key, and balance concepts. |
| apps/…/video-client.tsx | Shows the customer view of processing, playback, links, captions, deletion, and billing-related playback pauses. |
| apps/…/embed-options.tsx | Shows the player options that become customer embed code. |
| apps/…/webhooks-client.tsx | Shows endpoint setup, event selection, signing-secret handling, tests, and failure controls. |
| apps/…/page.tsx | Shows storage, transcription, delivery, and daily billing views. |
| apps/…/billing-view.tsx | Shows rates, prepaid balance, auto top-up, and the credit ledger. |
| apps/…/route.ts | Defines the public developer API groups. |
| apps/…/infra-video-upload.ts | Explains the shared create, multipart upload, admission, and completion lifecycle. |
| apps/…/developer-video-processing.ts | Shows how an accepted video becomes encoded outputs and how progress is settled. |
| apps/…/developer-video-playback.ts | Shows how playback IDs become signed HLS, MP4, and poster delivery. |
| apps/…/developer-transcript-store.ts | Connects transcript creation, idempotency, queueing, reads, deletes, and cleanup. |
| apps/…/developer-transcribe.ts | Shows the end-to-end source, audio, speech, and billing flow. |
| apps/…/infra-standing.ts | Defines credit standing, upload admission, pause behavior, and billing summaries. |
| apps/…/infra-storage-billing.ts | Defines daily storage snapshots and charge settlement. |
| apps/…/route.ts | Shows how scheduled cleanup covers multipart uploads, unrecorded files, and video purges. |