Learning resourcesReviewed · xAI

Photo to Time-Lapse (xAI Grok cookbook example)

Photo to Time-Lapse is an xAI cookbook walkthrough for developers who want to see how Grok image and video models can turn one photo into a ten-second time-lapse; the main catch is that it needs an xAI API key and the authors report about $1.72 per run. The page describes a TypeScript web and terminal app that plans stages with grok-4.7, edits the original photo once per stage, then pins those edits at set moments in one grok-imagine-video-1.5 video.

Researched 15 Nov 2026

In short.

Photo to Time-Lapse is an xAI cookbook walkthrough for developers who want to learn how Grok image and video models can turn one photo into a ten-second time-lapse; the main catch is that it needs an xAI API key and the authors report about $1.72 per run. The page describes a TypeScript example (Node.js 22.13 or later) with a web page and a terminal command. Grok (grok-4.7) plans the stages as streamed structured output. Each stage is an edit of the original photo, which keeps the scene consistent. One grok-imagine-video-1.5 job then passes through those edits as a first frame, up to four keyframes and a last frame. The page gives concrete limits, a cost breakdown and design reasons. It is author-written documentation: nothing was run for this report, and the source files it names were not part of the captured page.

Researched and written by an AI model and checked by a second AI model. How it works

The scope is the complete documentation page at [https://docs.x.ai/cookbook/examples/photo-to-time-lapse.md], captured once as a single text file. Linked pages, the repository source files the page names (src/timelapse.ts, src/server.ts, src/index.ts, public/index.html), the sample photo, any licence file, xAI pricing and terms pages, and SDK documentation were not captured and are excluded. No code was executed and the example was not run, so the commands, output quality, timings and costs are the authors' statements, not tested results.

The overview

What this is

This is a single documentation page titled Photo to Time-Lapse, from the xAI cookbook at [https://docs.x.ai/cookbook/examples/photo-to-time-lapse.md]. It describes an example app that uses Grok image and video models to build an AI time-lapse generator: you supply one photo and a described change, and you get a video of that scene changing over time.

The page points to example code under examples/photo-to-time-lapse/typescript in a repository. It names the files src/timelapse.ts, src/server.ts, src/index.ts and public/index.html. The page itself is the captured resource. The code files are described but were not captured.

Overall assessment

As a learning resource it is specific and well explained. It does not stop at a high-level demo. It names the models, states API constraints (keyframe count and timing grid), explains why each design choice was made, and reports a cost breakdown and rough run time. The reasoning for editing one photo repeatedly, instead of generating new images, is clearly argued and is the most reusable idea on the page.

It is an example, not a product. It shows a pattern for developers to adapt, and it depends on paid xAI API access. Its quality claims, such as first and last frames matching their stills and keyframes landing within a third of a second of their marks, are the authors' own observations from their runs. Nothing here independently verifies them.

Who it is for

The main audience is developers who already use or are evaluating the xAI API and want a worked example of chaining a reasoning model, image editing and video generation. It also suits people building keyframe-style video features, since the page explains pinning images at set moments.

Beginners can follow the described outcome and the run commands. They need to be comfortable with a terminal, Node.js, npm and getting an API key. Experienced developers will get the most from the How it works section, which covers structured streaming output, concurrent edits, long-job polling, temporary URLs, server-sent events and abort handling. People who only want to make a time-lapse video without writing or running code are not the target: the page offers no hosted app.

What it can do

According to the page, the example can: send a photo to Grok and stream back a plan as structured output (a title, the stages, and a sentence on how the scene moves between them); show Grok's reasoning as it arrives; edit the original photo once per stage; generate a single ten-second video that passes through those edits; and show progress while the video renders. It also saves the video before its temporary URL expires.

Users can pick a ready-made change or describe their own. The web page offers four seasons, empty lot to building, day to night and sketch to painting. The terminal accepts the presets seasons, day-to-night, sketch-to-painting and construction, or a change in your own words. You can upload your own photo or use the bundled sample street corner. The web page works like a keyframe editor: the plan appears on the left, each stage lands on a timeline at its mark, stills fill in as edits finish, and each pin lights up as the video plays. Clicking a pin jumps to it, and a Stop button cancels a run.

Both versions save the plan, stills and video to output/<title>/. The terminal version also writes an index.html there that plays the video above its pinned stills.

Using it

What you need

Stated requirements: Node.js 22.13 or later, and an xAI API key supplied either in a .env file at the root of the repo or exported as XAI_API_KEY. You also need the repository containing examples/photo-to-time-lapse/typescript, since the page tells you to change into that directory and run npm install.

Dependencies pulled in by npm install are not listed on the page. The page mentions an SDK at version 0.2.2 but does not name the package. Operating system support, browser requirements, memory or disk needs, and xAI account tier or rate limits are not stated. Network access to the xAI API is implied for planning, image editing and video generation.

How it works

The shared code in src/timelapse.ts runs five steps through makeTimeLapse(). First, planStages() sends the photo and the change request to grok-4.7 and streams back structured output: a title, stages (each with a label, an instruction for the image editor, and the second the video should reach it) and a sentence on how the scene moves. It reports reasoning as it arrives and each stage as soon as it is written. The authors say the plan usually takes under half a minute at the default reasoning effort.

Second, placeStages() maps stages onto the clip. The first stage becomes the first frame and the last becomes the last frame. Stages in between become keyframes. The API accepts at most four keyframes, strictly inside the clip, on a grid of thirds of a second, with no two in the same slot, so each is snapped to the grid and moved to the next free slot if needed.

Third, editPhoto() calls client.images.edit() for every stage, always starting from the original photo, and the edits run at the same time. The authors say this keeps the camera, framing and buildings identical in every still, so the video only has to animate the change.

Fourth, renderVideo() starts one ten-second grok-imagine-video-1.5 job through client.videos.generate(), using the first still as image, middle stills as keyframes and the final still as last_frame. The page says SDK 0.2.2 has keyframes but not last_frame, so last_frame is added with a type cast and its image is sent as a data URL because the SDK converts only Blobs in the fields it knows. Fifth, waitForVideo() polls client.videos.get() every five seconds to report the API's progress, which client.videos.wait() does not pass on. The video URL is temporary, so the video is downloaded as soon as it is done.

The web layer, src/server.ts, is a small node:http server. Because EventSource can only make GET requests, the page first uploads the photo to /api/photos, then opens /api/time-lapse with the returned id. The server streams progress as server-sent events and serves stills and the video with byte-range support so the browser can seek. An AbortSignal is passed to every API call, and the server aborts it when the page closes or Stop is clicked. public/index.html is plain HTML and JavaScript.

Setup and running it

Web version, as given on the page: put the API key in .env at the repo root or export XAI_API_KEY, then run cd examples/photo-to-time-lapse/typescript, npm install and npm run web. Then open [http://localhost:3000]. The sample street photo is already loaded, so you click Make time-lapse to run the four-seasons change, or pick another change, drop in your own photo, or describe your own change.

Terminal version: npm start -- ./your-photo.jpg day-to-night, or npm start -- ./your-photo.jpg "A field of tulips, from closed buds to full bloom". With no arguments it uses sample-street.jpg and the four seasons.

Not stated: how to obtain the repository, how to get an xAI API key, and which network interface the local server binds to. This report did not run any of these steps.

Worked example

The page's own example is the bundled sample photo of a street corner, which the authors say they made with grok-imagine-image-2.0. Choosing the four-seasons change leads Grok to plan stages for the seasons. Each stage is turned into an edit of the same street photo. One ten-second video is then rendered that begins on the first still, passes through the middle stills at their pinned seconds and ends on the last still. The authors say a typical run makes four images and one ten-second video.

Other changes named on the page are empty lot to building, day to night, sketch to painting, and a custom prompt such as a field of tulips going from closed buds to full bloom. The authors say a run takes two to four minutes. The page does not show the output video, the plan text or any generated still, and this report did not generate any, so output quality is not assessed.

Assessment & evidence

Limitations and risks

Stated by the page: the keyframe API takes at most four keyframes, strictly inside the clip, on a grid of thirds of a second, with no two in the same slot, so planned timings are snapped and may shift. The video is a fixed ten seconds in this example. The last_frame field is not yet supported by SDK 0.2.2 and is added through a cast, which is a fragile workaround that may change with SDK releases. Pinning the last stage as a keyframe a third of a second before the end also works, but the video then keeps changing after that pin and ends a little off the still. A started video job cannot be cancelled.

Not stated or not assessed: reliability across different photo types, whether the edit step keeps people, text or fine detail consistent, behaviour with large images or unusual formats, how failures or API errors are handled, content moderation behaviour of the models, and whether the local web server has any authentication or restricts access to localhost. The authors' accuracy observations (first and last frames matched, keyframes within about a third of a second, usually a little early) come from their runs only. The page presents a tutorial example; the page does not establish production readiness, and the supporting code files were not captured here.

Why the design makes sense

The central idea is to edit one photo for each stage instead of generating new images. The page's stated reason is that editing keeps the camera, framing and buildings the same in every still, so the video model only has to animate the change. Pinning those stills in one video job uses the API's first frame, keyframe and last frame fields.

Other choices follow from API constraints the page states. The keyframe grid logic exists because the API limits keyframes. Polling every five seconds exists because client.videos.wait() does not pass on progress. Downloading the video at once exists because its URL is temporary. Uploading the photo first and then opening an EventSource exists because EventSource can only make GET requests. These are the authors' reasons and are plausible, but this report did not execute the code to confirm them.

Alternatives and trade-offs

The page itself names two alternatives. One is pinning the last stage as a keyframe a third of a second before the end instead of using last_frame, which it says works but ends a little off the still. The other is using client.videos.wait() instead of its own polling loop, which it rejects because that call does not pass on progress. It also contrasts editing one photo with generating new images for each stage, saying editing keeps the scene identical.

The page does not compare this example with tools from other vendors or with non-AI time-lapse methods, and no such comparison was assessed. If you need a no-code tool, the example is not it. If you want to use another provider's models, the structure (plan, edit from one source, pin into one video) may transfer, but the specific keyframe limits and API calls here are for xAI's API.

Evidence and confidence

All findings come from one captured documentation page of about 6 KB. It appears in xAI's cookbook documentation; the page does not identify its author. Confidence is good that the page describes the example as it states, including the commands, requirements, models, API limits and reported cost. Confidence is low on real-world behaviour, because nothing was executed and no outputs, code or screenshots were captured.

Claims of the form in our runs and it cost $1.72 when we ran it are author-reported and unverified here. The page does not give dates, version numbers beyond SDK 0.2.2, Node.js 22.13 and the model names, test details or example outputs.

Access & freshness

Costs

The page gives one cost figure for one run: $1.72 when the authors ran it, made up of $0.07 for each image edit and $1.44 for the video. This matches four edits at $0.07 plus $1.44 for the ten-second video. The page says the images and video are nearly all of the cost, and both the page and the terminal show what the images and video cost at the end of a run.

Not established: the cost of the grok-4.7 planning call, current xAI pricing (the figures are as of the authors' run), pricing for different photo sizes or different numbers of stages, any free tier or credits, and any cost or licence terms for the repository code. One cost risk is stated explicitly: if a run is stopped or the page is closed after the video job has started, the video keeps rendering and is still billed, because the API cannot cancel a video job. Repeated runs multiply the spend.

Rights and licensing

The captured page states no licence for the example code, the sample photo or the page text, and no usage terms for generated images or videos. The licence of the repository is therefore unknown from this evidence. The same applies to who owns the output and what xAI's terms allow for commercial use of generated images and video.

The app sends your photo to the xAI API for planning, editing and video generation, as the page describes. How xAI stores or uses submitted images is not stated. If you use your own photo, you need the right to use it, and this matters most for photos of people, which the page does not address. The sample photo was generated by grok-imagine-image-2.0 according to the authors.

Freshness

The page was captured on 2026-11-15. It shows no publication or update date. It names grok-4.7, grok-imagine-video-1.5, grok-imagine-image-2.0, SDK 0.2.2 and Node.js 22.13 or later, and these may change. The page says SDK 0.2.2 does not yet have last_frame, so the workaround described is likely to change when the SDK adds it. The costs are tied to the authors' run and may differ from current xAI pricing.

What to do next

If you are a developer on the xAI API, read the How it works section first for the keyframe grid rules and the edit-from-the-original technique. Before running the example, check current xAI pricing, set a spending limit if the platform offers one, and remember that a started video job is billed even if you press Stop. Start with the sample photo for a first run so you can compare your result with the authors' two-to-four-minute and about $1.72 figures.

Before using your own photos, confirm you have the rights to them and check xAI's terms on data handling and commercial use of generated output, which this page does not cover. Look at the repository's licence directly before reusing the code. Treat the local server as a development tool and check how it binds before exposing it beyond your machine, since the page does not say. If you rely on the last_frame workaround, check the SDK release notes, because the page says that field is not yet supported in version 0.2.2.

Evidence for this report

selected-page.txtselected · checked 2026-11-15