Estimate an inference tool run's price
Viewing v2, the current version
curl --request POST \ --url https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inference-tools/:inference_tool_key/inferences/estimate \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "base_model_id": "<string>", "source_file_id": "<uuid>", "source_size": { "width": 0, "height": 0, "duration_seconds": 0 }, "source_transform": { "crop": { "x": 0, "y": 0, "width": 0, "height": 0 }, "rotate": 0 }, "mask_file_id": "<uuid>", "masked_edit_output": "composite", "batch_size": 1, "input": {}, "reference_sets": [], "session_id": "<uuid>", "session_name": "<string>"}'import requests
url = "https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inference-tools/:inference_tool_key/inferences/estimate"
payload = { "base_model_id": "<string>", "source_file_id": "<uuid>", "source_size": { "width": 0, "height": 0, "duration_seconds": 0 }, "source_transform": { "crop": { "x": 0, "y": 0, "width": 0, "height": 0 }, "rotate": 0 }, "mask_file_id": "<uuid>", "masked_edit_output": "composite", "batch_size": 1, "input": {}, "reference_sets": [], "session_id": "<uuid>", "session_name": "<string>"}headers = { "Authorization": "Bearer <token>", "Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())const url = 'https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inference-tools/:inference_tool_key/inferences/estimate';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"base_model_id":"<string>","source_file_id":"<uuid>","source_size":{"width":0,"height":0,"duration_seconds":0},"source_transform":{"crop":{"x":0,"y":0,"width":0,"height":0},"rotate":0},"mask_file_id":"<uuid>","masked_edit_output":"composite","batch_size":1,"input":{},"reference_sets":[],"session_id":"<uuid>","session_name":"<string>"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}package main
import ( "fmt" "strings" "net/http" "io")
func main() {
url := "https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inference-tools/:inference_tool_key/inferences/estimate"
payload := strings.NewReader("{\n \"base_model_id\": \"<string>\",\n \"source_file_id\": \"<uuid>\",\n \"source_size\": {\n \"width\": 0,\n \"height\": 0,\n \"duration_seconds\": 0\n },\n \"source_transform\": {\n \"crop\": {\n \"x\": 0,\n \"y\": 0,\n \"width\": 0,\n \"height\": 0\n },\n \"rotate\": 0\n },\n \"mask_file_id\": \"<uuid>\",\n \"masked_edit_output\": \"composite\",\n \"batch_size\": 1,\n \"input\": {},\n \"reference_sets\": [],\n \"session_id\": \"<uuid>\",\n \"session_name\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>") req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close() body, _ := io.ReadAll(res.Body)
fmt.Println(res) fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [ CURLOPT_URL => "https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inference-tools/:inference_tool_key/inferences/estimate", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode([ 'base_model_id' => '<string>', 'source_file_id' => '<uuid>', 'source_size' => [ 'width' => 0, 'height' => 0, 'duration_seconds' => 0 ], 'source_transform' => [ 'crop' => [ 'x' => 0, 'y' => 0, 'width' => 0, 'height' => 0 ], 'rotate' => 0 ], 'mask_file_id' => '<uuid>', 'masked_edit_output' => 'composite', 'batch_size' => 1, 'input' => [
], 'reference_sets' => [
], 'session_id' => '<uuid>', 'session_name' => '<string>' ]), CURLOPT_HTTPHEADER => [ "Authorization: Bearer <token>", "Content-Type: application/json" ],]);
$response = curl_exec($curl);$err = curl_error($curl);
curl_close($curl);
if ($err) { echo "cURL Error #:" . $err;} else { echo $response;}OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");RequestBody body = RequestBody.create(mediaType, "{\n \"base_model_id\": \"<string>\",\n \"source_file_id\": \"<uuid>\",\n \"source_size\": {\n \"width\": 0,\n \"height\": 0,\n \"duration_seconds\": 0\n },\n \"source_transform\": {\n \"crop\": {\n \"x\": 0,\n \"y\": 0,\n \"width\": 0,\n \"height\": 0\n },\n \"rotate\": 0\n },\n \"mask_file_id\": \"<uuid>\",\n \"masked_edit_output\": \"composite\",\n \"batch_size\": 1,\n \"input\": {},\n \"reference_sets\": [],\n \"session_id\": \"<uuid>\",\n \"session_name\": \"<string>\"\n}");Request request = new Request.Builder() .url("https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inference-tools/:inference_tool_key/inferences/estimate") .post(body) .addHeader("Authorization", "Bearer <token>") .addHeader("Content-Type", "application/json") .build();
Response response = client.newCall(request).execute();require 'uri'require 'net/http'
url = URI("https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inference-tools/:inference_tool_key/inferences/estimate")
http = Net::HTTP.new(url.host, url.port)http.use_ssl = true
request = Net::HTTP::Post.new(url)request["Authorization"] = 'Bearer <token>'request["Content-Type"] = 'application/json'request.body = "{\n \"base_model_id\": \"<string>\",\n \"source_file_id\": \"<uuid>\",\n \"source_size\": {\n \"width\": 0,\n \"height\": 0,\n \"duration_seconds\": 0\n },\n \"source_transform\": {\n \"crop\": {\n \"x\": 0,\n \"y\": 0,\n \"width\": 0,\n \"height\": 0\n },\n \"rotate\": 0\n },\n \"mask_file_id\": \"<uuid>\",\n \"masked_edit_output\": \"composite\",\n \"batch_size\": 1,\n \"input\": {},\n \"reference_sets\": [],\n \"session_id\": \"<uuid>\",\n \"session_name\": \"<string>\"\n}"
response = http.request(request)puts response.read_bodyvar client = new RestClient("https://api.app.layer.ai/api/v2/workspaces/:workspace_id/inference-tools/:inference_tool_key/inferences/estimate");var request = new RestRequest("", Method.Post);request.AddHeader("Authorization", "Bearer <token>");request.AddHeader("Content-Type", "application/json");request.AddParameter("application/json", "{\n \"base_model_id\": \"<string>\",\n \"source_file_id\": \"<uuid>\",\n \"source_size\": {\n \"width\": 0,\n \"height\": 0,\n \"duration_seconds\": 0\n },\n \"source_transform\": {\n \"crop\": {\n \"x\": 0,\n \"y\": 0,\n \"width\": 0,\n \"height\": 0\n },\n \"rotate\": 0\n },\n \"mask_file_id\": \"<uuid>\",\n \"masked_edit_output\": \"composite\",\n \"batch_size\": 1,\n \"input\": {},\n \"reference_sets\": [],\n \"session_id\": \"<uuid>\",\n \"session_name\": \"<string>\"\n}", ParameterType.RequestBody);var response = client.Execute(request);New in v2. This endpoint has no v1 equivalent.
Price a run of a Layer tool without starting it. The body is the run’s (POST …/inferences) without webhook, and the run is built as the run builds it, in the project of its session_id or the existing session its session_name finds, when it names one: the model named or the tool’s default for the caller, the values the tool fixes, the source and mask by ID, and the reference sets. Before an image or video source is uploaded, give its size as source_size in place of source_file_id: the run is priced as it would be with a file of that size, an image reframe’s source_transform included. A form still being filled in is priced as it stands, as the Layer app prices it. The body may leave out a prompt, the files of a file slot, a lighting, a camera move, or a reference set the model needs. A few inputs a provider’s own check needs are still required, such as a dub’s target_language and the files a few video models need. A prompt shorter than the model takes is accepted for pricing, though the run refuses it with PROMPT_TOO_SHORT. Where the price does not depend on what is missing or short, the estimate is the price of the completed run; where it does, such as speech priced by the length of its text, it is the price of the input as given. The source is still needed where the schema says x-source.required, as a file or by its size. Every other value the body gives is checked as the run checks it, a prompt longer than the model takes included, and one the run would refuse is refused here with the same error. The run alone checks what the workspace has left when it starts, so a run priced here can still be refused by the caller’s rate limit or a usage limit, or for the balance when has_sufficient_creative_units is false.
Authorizations
Section titled “Authorizations”Parameters
Section titled “ Parameters ”Path Parameters
Section titled “Path Parameters”ID of the workspace that owns the resource.
ID of the workspace that owns the resource.
Key of the inference tool, such as image.upscale, as returned by the list inference tools endpoint.
Key of the inference tool, such as image.upscale, as returned by the list inference tools endpoint.
Header Parameters
Section titled “Header Parameters”Opaque key making a retry of this request return the first result. A 2xx response is replayed for 24 hours with Idempotent-Replayed: true. A 4xx releases the key. A 5xx, or a request still running, holds the key for 120 seconds, during which a retry gets 409; after that a retry executes again. The key covers the method, path, query, and byte-identical body it was first used with; reusing it for a different request is rejected with 422. Protection is best effort: if the key store is unavailable, or a record is lost early, a retry can execute again even after an earlier 409. See the Idempotency section of the API description.
Request Bodyrequired
Section titled “Request Bodyrequired”object
The base model to run the tool on, by ID, slug, name or alias: one of the tool’s base_model_ids. Without it, the run takes the tool’s default_base_model_id for the caller.
The file an edit works on, from this workspace or public. Required where the tool’s schema has x-source.required; a tool that makes something new takes none.
An edit’s source by its size, before it is uploaded.
object
The source’s width in pixels, as displayed.
The source’s height in pixels, as displayed.
A video source’s length in seconds. Required for a video; an image takes none.
Where an image reframe puts its source in the frame: the source turned by rotate, then the frame
drawn over it as crop. The frame’s size in pixels is the run’s own, so the crop’s size sets how
large the source is in it.
object
The frame as a box over the source, in the source’s pixels after rotate. Its shape is the frame’s, the one input.aspect_ratio sets, to within 1.5%; its size against the source’s sets the source’s scale in the frame: a crop twice the source’s width shows the source at half the frame’s width. On an AUTO aspect ratio the crop is the frame, at the size the model renders.
object
The frame’s left edge, in the source’s pixels from the source’s left edge, or from its bounding box’s when rotate turns it. Negative where the frame starts left of the source: the model fills that area.
The frame’s top edge, in the source’s pixels from the source’s top edge, or from its bounding box’s when rotate turns it. Negative where the frame starts above the source: the model fills that area.
The frame’s width in the source’s pixels. Where the frame reaches past the source’s right edge, the model fills that area.
The frame’s height in the source’s pixels. Where the frame reaches past the source’s bottom edge, the model fills that area.
Degrees to turn the source clockwise about its center before the crop, -360 to 360. The turned source’s canvas grows to its bounding box, the source centered in it, and crop is measured from that box’s top-left corner.
An image the size of the source, white where the edit may change it and black where the source stays as it is. Only where the tool’s schema has x-source.takes_mask.
What a masked edit returns. The outcomes exclude each other: a run returns one of them.
How many outputs the run makes (1-16). More than 1 needs a tool and a model that batch.
The fields of the tool’s schema on the model (GET …/inference-schema), with files by file_id. A field left out takes the model’s default from the AI policy in force for the run, else its own default, and the tool sets the values it fixes. A run needs every field the schema requires; an estimate prices the form as it stands, so it may leave some of them out.
object
Reference sets to apply, up to 25, from GET /v2/workspaces/{workspace_id}/reference-sets. Some models need one: an ElevenLabs voice for a voice change or speech, an animation preset for Tripo’s animate. A run on such a model without one is refused with REFERENCE_SET_REQUIRED; an estimate prices it without one.
object
Reference set ID from GET /v2/workspaces/{workspace_id}/reference-sets.
Weight for the set’s LoRA adapter when one applies. Ignored for sets applied as reference images or prompt text.
Organize this run under this session, from GET /v2/workspaces/{workspace_id}/sessions. Takes precedence over session_name, and must belong to this workspace. Its project’s AI policy decides the models the run may take and their defaults; an estimate with it prices the run in that project.
Organize this run under the most recent active session with this name, creating one if none matches. Ignored when session_id is given. An estimate with it prices the run in that session’s project, or in the workspace when no session has the name yet.
Responses
Section titled “ Responses ”Successful Response
object
Total estimated Creative Units price for this run.
Usable Creative Units balance (total balance minus reserved by in-progress generations).
Usable balance after subtracting the estimated price. Can be negative.
Whether the workspace has enough available Creative Units to cover the estimated price.
Whether the workspace is exempt from the balance check.
The base model the run takes: the one named, else the tool’s default.
Per-set summary of what each reference set would contribute to this run.
object
Reference Set ID this contribution belongs to, if any.
True when the set’s trained finetune (a LoRA, or a Recraft style) was applied.
True when an animation (Meshy rigging action) finetune was applied for this set.
True when a voice (ElevenLabs) finetune was applied for this set.
Number of assets successfully mapped to guidance inputs.
True when the set’s palette went into the run’s color palette (up to the model’s color limit), or a palette passed with the request stood in for it.
True when the set fell back to prompt-only representation.
True when the set’s auto prompt addition was appended to the prompt. Informational: the text rides on top of whatever else the set contributed and is not a degradation.
True when SBMC has a LoRA for this set on another base model but not the one used.
True when the set isn’t applicable to the chosen model (its modality / applicable base models exclude it) so no LoRA or assets were applied.
True when the set’s category means nothing for the chosen model’s modality (a camera move on an image model), so it was dropped entirely, prompt text included. Implies skipped_not_applicable.
True when at least one attached reference set would not meaningfully contribute on the base model.
Names each degraded reference set and why, or null when none is degraded.
Example
{ "allow_negative_balance": false, "reference_set_contributions": [], "reference_sets_degraded": false}Unauthenticated — missing or invalid Bearer token.
object
Machine-readable error code: the last path segment of type.
The request field the error is about, by its name in the body (on a tool run, in input), on the errors that name one: so far the value a Layer tool fixes on an INFERENCE_TOOL_PIN_MISMATCH, and the scale factor on an INFERENCE_TOOL_UPSCALE_COPIES_SOURCE. Absent otherwise, even when detail names a field.
Example
{ "type": "https://api.layer.ai/errors/ERROR_CODE", "title": "Error Title", "status": 400, "detail": "Human-readable description.", "error_code": "ERROR_CODE", "field": "tileability"}Forbidden — insufficient permissions, or the access token lacks the scope the operation requires.
object
Machine-readable error code: the last path segment of type.
The request field the error is about, by its name in the body (on a tool run, in input), on the errors that name one: so far the value a Layer tool fixes on an INFERENCE_TOOL_PIN_MISMATCH, and the scale factor on an INFERENCE_TOOL_UPSCALE_COPIES_SOURCE. Absent otherwise, even when detail names a field.
Example
{ "type": "https://api.layer.ai/errors/ERROR_CODE", "title": "Error Title", "status": 400, "detail": "Human-readable description.", "error_code": "ERROR_CODE", "field": "tileability"}Resource not found.
object
Machine-readable error code: the last path segment of type.
The request field the error is about, by its name in the body (on a tool run, in input), on the errors that name one: so far the value a Layer tool fixes on an INFERENCE_TOOL_PIN_MISMATCH, and the scale factor on an INFERENCE_TOOL_UPSCALE_COPIES_SOURCE. Absent otherwise, even when detail names a field.
Example
{ "type": "https://api.layer.ai/errors/ERROR_CODE", "title": "Error Title", "status": 400, "detail": "Human-readable description.", "error_code": "ERROR_CODE", "field": "tileability"}The outcome of the request with this Idempotency-Key is not known yet: it is still running, or it failed without a stored response. Retry after the number of seconds in Retry-After.
object
Machine-readable error code: the last path segment of type.
The request field the error is about, by its name in the body (on a tool run, in input), on the errors that name one: so far the value a Layer tool fixes on an INFERENCE_TOOL_PIN_MISMATCH, and the scale factor on an INFERENCE_TOOL_UPSCALE_COPIES_SOURCE. Absent otherwise, even when detail names a field.
Example
{ "type": "https://api.layer.ai/errors/ERROR_CODE", "title": "Error Title", "status": 400, "detail": "Human-readable description.", "error_code": "ERROR_CODE", "field": "tileability"}Invalid input parameters, or an Idempotency-Key reused for a different request.
object
Machine-readable error code: the last path segment of type.
The request field the error is about, by its name in the body (on a tool run, in input), on the errors that name one: so far the value a Layer tool fixes on an INFERENCE_TOOL_PIN_MISMATCH, and the scale factor on an INFERENCE_TOOL_UPSCALE_COPIES_SOURCE. Absent otherwise, even when detail names a field.
Example
{ "type": "https://api.layer.ai/errors/ERROR_CODE", "title": "Error Title", "status": 400, "detail": "Human-readable description.", "error_code": "ERROR_CODE", "field": "tileability"}Rate limited — retry after the number of seconds in Retry-After.
object
Machine-readable error code: the last path segment of type.
The request field the error is about, by its name in the body (on a tool run, in input), on the errors that name one: so far the value a Layer tool fixes on an INFERENCE_TOOL_PIN_MISMATCH, and the scale factor on an INFERENCE_TOOL_UPSCALE_COPIES_SOURCE. Absent otherwise, even when detail names a field.
Example
{ "type": "https://api.layer.ai/errors/ERROR_CODE", "title": "Error Title", "status": 400, "detail": "Human-readable description.", "error_code": "ERROR_CODE", "field": "tileability"}Internal server error.
object
Machine-readable error code: the last path segment of type.
The request field the error is about, by its name in the body (on a tool run, in input), on the errors that name one: so far the value a Layer tool fixes on an INFERENCE_TOOL_PIN_MISMATCH, and the scale factor on an INFERENCE_TOOL_UPSCALE_COPIES_SOURCE. Absent otherwise, even when detail names a field.
Example
{ "type": "https://api.layer.ai/errors/ERROR_CODE", "title": "Error Title", "status": 400, "detail": "Human-readable description.", "error_code": "ERROR_CODE", "field": "tileability"}