> ## Documentation Index
> Fetch the complete documentation index at: https://docs.f13.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Create an API key and stream your first SVG

## 1. Create an API key

API keys are managed in the [dashboard](https://app.f13.com) under
**Settings → API keys**. Keys belong to a workspace; requests made with a key
are billed to that workspace and its assets land in that workspace's library.

A key looks like this and is shown **once** at creation:

```text theme={null}
f13_sk_live_AbCd1234…
```

Store it in a secret manager or environment variable - you cannot retrieve it
again later, only revoke it and create a new one.

> [!WARNING]
>
> There is no separate test mode. Every key is a live key, and every successful
> generation is billed. New personal workspaces include a small free credit
> grant so you can experiment before adding a payment method.

## 2. Make your first request

```bash theme={null}
curl -N https://api.f13.com/v1/generations \
  -H "Authorization: Bearer $F13_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "a minimal line-art icon of a paper plane"
  }'
```

The `-N` flag disables curl's buffering so you see the stream live. The
response is a server-sent event stream: a series of `data:` lines, each
carrying one JSON object.

```text theme={null}
data: {"type":"delta","text":"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"}

data: {"type":"delta","text":"<path d=\"M2 21l21-9L2 3v7l15 2-15 2z\"/>"}

data: {"type":"saved","asset":{"id":"9b2f…","svgUrl":"https://…", "costCents":3, …}}

data: {"type":"done"}
```

Concatenate the `delta` texts to get the SVG markup as it streams. The
`saved` event carries the stored asset - its `id`, hosted `svgUrl`, cost, and
latency. `done` closes the stream. The full event flow, including error
frames, is described in [Streaming](https://docs.f13.com/streaming.md).

## 3. Consume the stream from code

The endpoint is a `POST`, so the browser `EventSource` API does not apply -
read the body stream directly:

```typescript theme={null}
const res = await fetch("https://api.f13.com/v1/generations", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.F13_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ prompt: "a minimal line-art icon of a paper plane" }),
});

if (!res.ok) {
  throw new Error(`F13 error ${res.status}: ${await res.text()}`);
}

const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
let svg = "";

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  buffer += decoder.decode(value, { stream: true });

  const frames = buffer.split("\n\n");
  buffer = frames.pop() ?? "";
  for (const frame of frames) {
    if (!frame.startsWith("data: ")) continue;
    const event = JSON.parse(frame.slice(6));
    switch (event.type) {
      case "delta":
        svg += event.text;
        break;
      case "saved":
        console.log("asset saved:", event.asset.id, event.asset.svgUrl);
        break;
      case "error":
        throw new Error(event.message);
    }
  }
}

console.log(svg); // the complete SVG markup
```

## 4. Retry safely with an idempotency key

Network failures happen mid-stream. Send an `Idempotency-Key` header so a
retry never bills you twice:

```bash theme={null}
curl -N https://api.f13.com/v1/generations \
  -H "Authorization: Bearer $F13_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 4f9d36c0-order-hero-icon" \
  -d '{"prompt": "a minimal line-art icon of a paper plane"}'
```

If the original request completed, the retry replays its result (the finished
SVG as one `delta`, then the `saved` and `done` events) instead of
generating - and paying - again. Keep one key per request: the same key with
a different prompt is rejected with `422`. Details in the
[API reference](https://docs.f13.com/api-reference/introduction.md#idempotency).

## Next steps

For the full picture of the API, continue with:

* [Streaming - the full event flow: frame types, ordering, and failure modes.](https://docs.f13.com/streaming.md)
* [POST /v1/generations - every request field and response property.](https://docs.f13.com/api-reference/generations.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.