Quickstart: store a file and ask a model about it
Install the SDK, upload a file to storage, read it back, and ask a model to summarise it.
This quickstart writes a short note to a bucket, reads it back, and asks a model to summarise it in Swahili. It uses space.fs and space.ai.
Before you begin
- Node 20.3 or newer, Bun, or Deno.
- A project. Copy its ID from Settings in the console.
- An API key. In the console, open API keys and create one with these permissions:
- Storage buckets: Create and View.
- Storage files: Upload, and View and download.
- AI: Call models.
See API keys.
Store a file and ask about it
Install the package
In a new folder:
npm install digitospaceSet your keys and project
export DIGITOSPACE_API_KEY="dsk_…" export DIGITOSPACE_PROJECT="your-project-id"Write the script
The script creates a bucket named
notesif the project does not have one, writes a file to it, reads the file back, and sends its text to a model.quickstart.mts import { isSpaceError, space } from "digitospace" try { await space.fs.buckets.create("notes") } catch (error) { if (!isSpaceError(error) || error.code !== "bucket_name_taken") throw error } await space.fs.write( "notes/today.txt", "The ferry to Zanzibar leaves Dar es Salaam at 7:00 and takes 2 hours." ) const text = await space.fs.read("notes/today.txt", { as: "text" }) const reply = await space.ai.chat(`Summarise this in Swahili: ${text}`, { model: "openai/gpt-oss-20b", }) console.log(reply.text) console.log(reply.usage)Run it
npx tsx quickstart.mtsThe summary prints first, then the call’s usage:
inputTokensandoutputTokensare the tokens the model read and wrote, andunitsis the AI units the call used.
If a call fails, the error names what went wrong in its code and message. See Handle errors.
What’s next
- Install and set up the SDK in your own app.
- Read write() and read() for every way to send and fetch a file.
- Stream answers as they are written with chat().
- Call your app on a schedule with every().
Last updated