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

# API keys and billing

> Create and manage Krea API keys, top up your workspace API balance, and review per-model pricing to plan integration costs across image and video models.

Explore the Krea APIPlans, capabilities, and what you can build with the API.



[Open](https://www.krea.ai/features/api)

## Creating API Keys

There are two kinds of API tokens:

* **Personal API tokens** act as **you**: requests run under your own Krea account, with your workspace role and access to your styles. Any workspace member can create one, and a personal token stops working if you leave the workspace.
* **Service API tokens** act as a **separate service user** in your workspace, not as the person who created them. Only workspace **owners** and **admins** can create them. Service tokens keep working if their creator leaves the workspace. Workspace **owners** and **admins** can see every token in the workspace, with 30-day spend tracked per service token.

To create an API key:

1. Go to [krea.ai/app/api/tokens](https://www.krea.ai/app/api/tokens)
2. Click **Create Personal Token** or **Create Service Token**
3. Give your key a descriptive name
4. Save the token securely — you'll only see it once!

> [!NOTE]
>
> Personal API tokens operate as your own Krea account, so styles you've trained in the app are available to them directly. Service API tokens operate as a separate user identity within your workspace: styles trained in the app won't be accessible via a service token, and styles trained via a service token won't appear in the app, unless they are shared with the workspace. See [Train a Custom Style](https://www.krea.ai/docs/developers/tutorials/train-image-style.md#use-your-trained-style) for details.

> [!WARNING]
>
> **Security Guidelines**
>
> * Store tokens in environment variables, never in code
> * Use different tokens for development and production
> * Revoke tokens immediately if compromised
> * Never commit tokens to version control
> * Never share tokens publicly

## Using API Keys

Include your token in the `Authorization` header of all requests:

```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"vesper"}}
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

const job = await krea.image("bfl/flux-1-dev", {
  prompt: "a serene mountain landscape at sunset",
  width: 1024,
  height: 576
});

console.log(`Job ID: ${job.job_id}`);
```

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
curl -X POST https://api.krea.ai/generate/image/bfl/flux-1-dev \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "a serene mountain landscape at sunset",
    "width": 1024,
    "height": 576
  }'
```

```python Python theme={"theme":{"light":"github-light-default","dark":"vesper"}}
import requests

API_BASE = "https://api.krea.ai"
API_TOKEN = "your-api-token"

response = requests.post(
    f"{API_BASE}/generate/image/bfl/flux-1-dev",
    headers={
        "Authorization": f"Bearer {API_TOKEN}",
        "Content-Type": "application/json"
    },
    json={
        "prompt": "a serene mountain landscape at sunset",
        "width": 1024,
        "height": 576
    }
)

job = response.json()
print(f"Job ID: {job['job_id']}")
```

```go Go theme={"theme":{"light":"github-light-default","dark":"vesper"}}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    apiBase := "https://api.krea.ai"
    apiToken := "your-api-token"

    payload := map[string]interface{}{
        "prompt": "a serene mountain landscape at sunset",
        "width":  1024,
        "height": 576,
    }

    jsonData, _ := json.Marshal(payload)
    req, _ := http.NewRequest("POST", apiBase+"/generate/image/bfl/flux-1-dev", bytes.NewBuffer(jsonData))
    req.Header.Set("Authorization", "Bearer "+apiToken)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()

    var job map[string]interface{}
    json.NewDecoder(resp.Body).Decode(&job)
    fmt.Printf("Job ID: %s\n", job["job_id"])
}
```

## Pricing

For per-model prices, see [krea.ai/app/api/pricing ↗](https://www.krea.ai/app/api/pricing). Every model has a fixed per-generation price determined by your request parameters (resolution, quality, audio, duration, style references, etc.).

## How API Billing Works

Direct API calls and MCP connections that use an API token draw from your workspace's **API balance** — separate from the workspace's compute unit balance used by the Krea web app. MCP connections that use OAuth are billed to the signed-in Krea account using compute units. API access must be enabled on your workspace before you can use API keys; if it isn't, contact [support@krea.ai ↗](mailto:support@krea.ai).

> [!NOTE]
>
> The [Agent API](https://www.krea.ai/docs/developers/agent.md) and Agent tools are an exception: Agent turns use the workspace's compute unit balance, including when authenticated with an API key. They do not use the API balance.

> [!TIP]
>
> Failed and cancelled jobs are not billed. You only pay for completed jobs.

### When your balance runs out

In-flight jobs finish normally. New API requests are rejected with **HTTP 402 Payment Required**:

```json theme={"theme":{"light":"github-light-default","dark":"vesper"}}
{
  "message": "Your API balance is separate from your workspace compute balance. Please top up your API balance to continue using the API."
}
```

Top up at [krea.ai/app/api/](https://krea.ai/app/api/) to resume. There is no public endpoint for checking your balance programmatically — monitor it in-app.

That body is the API-balance `402`. Zero Data Retention and other `402` responses are listed in [Errors and debugging](https://www.krea.ai/docs/developers/errors-and-debugging.md).

## Adding API Balance

Add funds at [krea.ai/app/api/](https://krea.ai/app/api/). Only workspace **owners** can add API balance.

* **Preset amounts:** \$10, \$25, \$50, \$100
* **Custom amount:** \$5 minimum, \$10,000 maximum
* Paid via Stripe Checkout; balance applies immediately on success

## Tracking Usage

See the API Usage page at [krea.ai/app/api/usage](https://www.krea.ai/app/api/usage) for completed API jobs and estimated costs over a selectable date range. Workspace managers see usage for the whole workspace; other members see usage from their own tokens. The API balance card at [krea.ai/app/api/](https://krea.ai/app/api/) also shows the estimated API cost for the last 7 days.

## Enterprise

> [!NOTE]
>
> Higher-volume customers can be invoiced monthly on Net 30 terms instead of prepaying. Contact [sales@krea.ai ↗](mailto:sales@krea.ai) to discuss enterprise billing.

## Next Steps

> [card] [Interactive Playground](https://www.krea.ai/docs/developers/interactiveexample.md)
>
> Make your first API request

> [card] [Model APIs](https://www.krea.ai/docs/api-reference/introduction.md)
>
> Explore all available endpoints

> [card] [Job Lifecycle](https://www.krea.ai/docs/developers/job-lifecycle.md)
>
> Understand job states and polling

> [card] [Rate Limits](https://www.krea.ai/docs/developers/rate-limits.md)
>
> Understand API limits by plan tier


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