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

  1. Install the package

    In a new folder:

    npm install digitospace
  2. Set your keys and project

    export DIGITOSPACE_API_KEY="dsk_…"
    export DIGITOSPACE_PROJECT="your-project-id"
  3. Write the script

    The script creates a bucket named notes if 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)
  4. Run it

    npx tsx quickstart.mts

    The summary prints first, then the call’s usage: inputTokens and outputTokens are the tokens the model read and wrote, and units is 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

Last updated