Hosted URLs
Store one URL per image instead of the file: it never expires and loads from our CDN, with no key and no API call.
/api/v1/hosted-urlsStore the URL, not the file
<img>.A hosted URL is built for exactly the job self-hosting tries to do:
- It never expires and never changes. Ask once, store it beside the vehicle, and serve it to every visitor for as long as your plan is active. There is nothing to renew or regenerate.
- No API call when a page loads. The page holds a plain URL, never your key; our CDN answers it.
- No storage, egress or CDN of your own. Every page that shows the image shares one cached copy on our CDN.
format: "auto"sends WebP to browsers that take it and PNG to the rest, at the width you asked for, so each visitor downloads the smallest file their screen needs. - Images get better on their own. When a render is improved or corrected, the same URL serves the new one. A copy you saved stays as it was.
- Nothing extra on the bill. Creating the URL is free. Each image counts once per calendar month as one vehicle image, the first time it loads that month, however many people see it and at any size; every other load is free.
A catalog or inventory: create the URLs once, store them
When the vehicles are known in advance (listings, a fleet, a product catalog), call POST /api/v1/hosted-urls once per vehicle when it enters your catalog, up to 100 images a call, and store each url. Get the vehicle ids from a free check of your list. Asking again for the same image returns the same URL, so a re-run is harmless.
# once per vehicle, when it enters your catalog: free, nothing is counted here
curl --fail-with-body -X POST https://carimage.dev/api/v1/hosted-urls \
-H "Authorization: Bearer $CAR_IMAGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"images":[
{"vehicle":"veh_395yw8tn73ff8","view":"front-3-4","color":"red","width":800,"height":600,"trim":true,"format":"auto"},
{"vehicle":"veh_errc87t1jgata","view":"side","color":"white","width":800,"height":600,"trim":true,"format":"auto"}]}'
# → data[0].url: "https://carimage.dev/i/veh_395yw8tn73ff8/front-3-4.auto?color=red&h=600&k=0b7c5c1e-…&trim=1&w=800&sig=9c41…"
# expires_at: null (it never expires; asking again returns the same URL)-- one column, filled once
alter table listings add column car_image_url text;
update listings set car_image_url = $1 where id = $2;
<!-- every page, for every visitor: no key, no API call, no file of yours -->
<img src="{{ listing.car_image_url }}" width="800" height="600" loading="lazy" alt="2023 Ford F-150, front three-quarter, red">import { setTimeout as sleep } from "node:timers/promises";
// Fill car_image_url for every listing that has none, 100 images a call.
const rows = await db.query("select id, vehicle_id from listings where car_image_url is null");
for (let i = 0; i < rows.length; i += 100) {
const batch = rows.slice(i, i + 100);
const response = await fetch("https://carimage.dev/api/v1/hosted-urls", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.CAR_IMAGE_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
images: batch.map((row) => ({ vehicle: row.vehicle_id, view: "front-3-4", width: 800, height: 600, trim: true, format: "auto" })),
}),
});
if (!response.ok) throw new Error(await response.text());
const { data } = await response.json(); // one { url } per image, in request order
for (const [n, row] of batch.entries()) {
await db.query("update listings set car_image_url = $1 where id = $2", [data[n].url, row.id]);
}
await sleep(500);
}No call at all: sign the URL on your server
The same URL can be built on your server with the key's signing secret, with no request to us: useful when pages are rendered from data that changes, or to skip the backfill. Make the secret once in the dashboard or with POST /api/v1/signing-secrets (how signing works, with a Python version). The React <CarImage> server component does this for you (React & Next.js).
import { carImageUrl } from "@meterapp/car-image-sdk";
// The key id and its signing secret live on your server; the URL is the same one
// POST /api/v1/hosted-urls returns, computed here without a request to us.
const src = await carImageUrl(
{ vehicle: listing.vehicleId, view: "front-3-4", color: "red", width: 800, height: 600, trim: true, format: "auto" },
{ keyId: process.env.CAR_IMAGE_KEY_ID!, signingSecret: process.env.CAR_IMAGE_SIGNING_SECRET! }
);Your users pick the car: search in the browser, sign on your server
A configurator, a quote form or a garage where people choose any vehicle needs no stored list. Vehicle search (GET /api/v1/vehicles?q=) is free and needs no key, so the browser can drive the autocomplete itself. When the user picks a car, the browser asks your server for its URL, and your server signs it locally. The key and the signing secret never reach the browser, and nothing calls us per image.
// app/api/car-image/route.ts: your server, the only place the signing secret lives
import { carImageUrl } from "@meterapp/car-image-sdk";
const VIEWS = new Set(["front-3-4", "side", "rear-3-4"]);
export async function GET(request: Request) {
const params = new URL(request.url).searchParams;
const vehicle = params.get("vehicle") ?? "";
const view = params.get("view") ?? "front-3-4";
// This route signs for your allowance: accept only what your product shows.
if (!/^veh_[0-9a-z]{13}$/.test(vehicle) || !VIEWS.has(view)) return new Response(null, { status: 400 });
const url = await carImageUrl(
{ vehicle, view, width: 800, format: "auto" },
{ keyId: process.env.CAR_IMAGE_KEY_ID!, signingSecret: process.env.CAR_IMAGE_SIGNING_SECRET! }
);
// Same input, same URL: let browsers and your CDN keep the answer.
return Response.json({ url }, { headers: { "Cache-Control": "public, max-age=86400" } });
}// In the browser: search needs no key, picking a car asks your server for its URL.
async function search(text) {
const response = await fetch(`https://carimage.dev/api/v1/vehicles?q=${encodeURIComponent(text)}&limit=8`);
return (await response.json()).data.results; // model hits carry ids: { "2024": "veh_…" }
}
async function show(vehicleId) {
const { url } = await (await fetch(`/api/car-image?vehicle=${vehicleId}&view=front-3-4`)).json();
document.querySelector("#car").src = url; // served from our CDN
}What to know
- Sizes for retina. Another width of the same vehicle, paint and view is the same vehicle image: a
srcsetof 400 and 800 px counts once. - Not prepared yet? The first load of a view we have not prepared answers
409and queues it, counting nothing; the same URL shows the image once it is ready. Availability says ahead of time, for free. - Plan and key. The URLs serve while your account can pay for each image's first load of the month; past the allowance, or after a plan ends, that load answers
402until it fits again. Rotating the key's signing secret or revoking the key ends its URLs, so keep one key for them. Stored files would be no different: on a plan, copies are deleted within 30 days after it ends. - When you really need files. Print, an offline app bundle or a document need the bytes. A plan delivers a limited number of different images a month as files (250 on Pro, 1,000 on Business). To own a set and host it forever, buy an Image Pack.