Investigate pricing information from Lambda Labs #145
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Our current implementation of vision_workers for Nidus Reveal attempts to track cost internally by keeping track of the price of an instance and how long we think it stays up. We control this, but it may introduce some timekeeping error compared to what our provider measures.
I'd like you to look at the Lambda Labs API documentation and determine if it would be possible to use their API to track price. This would allow our systems to be exactly in sync. If it's possible, I'd like a detailed writeup of how it would be done.
Investigation: Lambda Labs API for Price Tracking
I dove into the Lambda Labs Cloud API documentation and examined how our current vision_worker cost tracking works.
Current Approach
The vision_worker table has a cost_per_hour column that an operator sets manually when registering a worker. The system tracks first_poll_at, last_heartbeat, and shutdown_at timestamps, then the total cost is time × this manually-entered price. The concern is that if our internal timekeeping drifts from what the provider measures, we get a mismatch.
Lambda Labs API: What It Offers
The API provides pricing through GET /api/v1/instance-types, which returns every instance type with its authoritative price_cents_per_hour. For example:
Each running instance returned by GET /api/v1/instances also includes the full instance_type object with price_cents_per_hour baked in.
What the API does NOT provide:
The only lifecycle statuses are: booting, active, unhealthy, terminated, terminating, preempted — but there is no uptime or "total cost so far" exposed in the instance object.
Can We Use It for Price Tracking?
Yes, partially. There are three areas where the API improves our current approach:
1. Authoritative Instance-Type Pricing (Eliminates Manual Entry)
Instead of having an operator enter cost_per_hour during registration, we can call GET /api/v1/instance-types and look up the real price_cents_per_hour for the instance type. This eliminates the risk of stale or incorrect operator-entered prices.
Implementation sketch:
2. Instance Lifecycle Tracking via Provider ID
The API exposes instance status changes, but it is poll-based — you poll /instances or /instances/{id} to see current status. The statuses include preempted, terminated, terminating, which you could use to detect when billing stops.
Limitation: The API doesn't expose exact timestamps for state transitions (only current state). So you still need to record the time when you see the termination to calculate duration.
3. Instance Type ↔ Price Mapping
Since GET /api/v1/instances/{id} includes the full instance_type with price_cents_per_hour, you could periodically confirm that the price you're tracking matches the API. This works as a cross-check that catches pricing surprises.
What Can't Be Done
The API does not provide:
Since Lambda bills in wall-clock time (like most cloud GPU providers — you pay per hour or partial hour that the instance is active), our internal first_poll_at → shutdown_at tracking using the same instance lifecycle events as Lambda would give us the same wall-clock duration Lambda uses. The remaining gap would be partial-hour rounding, which we'd handle the same way Lambda does.
Summary
Bottom line: Using the Lambda Labs API to look up pricing is definitely possible and eliminates the manual-entry error. It gets us the authoritative price that Lambda charges, which is the biggest source of inaccuracy. The duration tracking has to remain our own because Lambda doesn't expose billed time, but we can mitigate any discrepancy by using the same wall-clock semantics as the provider (i.e., price_cents_per_hour × wall-clock hours the instance was active).
If you'd like me to create a feature branch with the implementation, I can start by:
Let me know how deep you want me to go on this!
Okay, thanks for digging in to this. Here's what I'm thinking we want to do:
I'd like you to create a pull request to implement this
PR #146 is ready with the implementation:
started_atandtotal_costcolumns tovision_workerEstimateCost()on the provider driver, stores the authoritativecost_per_hourand setsstarted_at(shutdown_at - started_at) × cost_per_hour, storestotal_cost, and logs the summaryplatform/andresource/to preferstarted_atovercreated_atwhen availableThe pricing capture is provider-agnostic (both Lambda Labs and DigitalOcean implement
EstimateCost()), so it works for both without special-casing.