# Stream LLM Response

`POST /compute/llms/{modelId}/invoke-stream` · Core · Compute & Automation

Dispatches an inference request to the specified LLM model and streams the response as Server-Sent Events (SSE), delivering tokens incrementally for low-latency UX. Requires `PROJECT_AUTHOR` or `PROJECT_ADMIN` as an LLM cost gate. Returns `K9O_LLM_MODEL_UNAVAILABLE` (404) when the requested model identifier is not in the curated library (every listed model is available on every plan), and `K9O_LLM_PROVIDER_UNAVAILABLE` (503) when an external provider is unreachable.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `modelId` | path | yes | The model's id, as the model list returns it. Example: `"mistral-7b"`. |
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `prompt` | string | yes | The prompt, sent to the model as a single user message. 1 to 100,000 characters. |
| `maxTokens` | integer | no | The most tokens the model may generate, 1 to 32,000. Default: the model server's own limit. |
| `temperature` | number | no | Sampling temperature, 0 to 2. Lower is more deterministic. Default: the model server's own. |
| `usageType` | string | no | A label of your own for this call, echoed back in the response. Default `sdk.direct`. |

## Responses

- **200**: The reply, streamed as server-sent events.

## Errors

| HTTP | Code | When |
|---|---|---|
| 400 | `K9O_MODEL_NOT_DECLARED` | The model identifier is not declared in the extension's manifest compatibility list. |
| 401 | `K9O_INVALID_CREDENTIALS` | The request credentials are missing or invalid. |
| 401 | `K9O_SESSION_EXPIRED` | Your session has expired; sign in again to continue. |
| 402 | `K9O_OUT_OF_TOKENS` | The org's included inference credit is used up and its wallet cannot cover the call (W9-Billing's inference gate). Never raised for your own provider (BYOM). |
| 403 | `K9O_ACCESS_DENIED` | Your role does not permit direct LLM streaming inference; PROJECT_AUTHOR or PROJECT_ADMIN is required. |
| 502 | `K9O_UPSTREAM_UNAVAILABLE` | The inference credit check is unavailable, so the model was not called; retry. |
| 503 | `K9O_LLM_PROVIDER_UNAVAILABLE` | The external LLM provider is temporarily unreachable; please retry with exponential backoff. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/compute/llms/<modelId>/invoke-stream' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/compute/llms/<modelId>/invoke-stream', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({}),
});
const { data, meta } = await res.json();
```

### k9o CLI

```bash
k9o function invoke <name>
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.functions.invoke('mistral-7b', {})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.functions.invoke("mistral-7b", {})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Functions.Invoke(ctx, "mistral-7b", map[string]any{})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.functions.invoke("mistral-7b", json!({})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.functions().invoke("mistral-7b", Map.of())
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Functions.InvokeAsync("mistral-7b", new Dictionary<string, object> {  })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.functions.invoke("mistral-7b", {  })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->functions->invoke('mistral-7b', [])
```

### K9o

```swift
// let k9o = try K9o.createClient(orgSlug: "playground", projectSlug: "storefront", apiKey: "k9o_…")
let result = try await k9o.functions.invoke("mistral-7b", {})
```

### core-kotlin

```kotlin
// val k9o = createClient { orgSlug = "playground"; projectSlug = "storefront"; apiKey = "k9o_…" }
val result = k9o.functions.invoke("mistral-7b", {})
```

### k9o (Flutter)

```dart
// final k9o = K9o.createClient(orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…');
final result = await k9o.functions.invoke('mistral-7b', {})
```

### @k9o/react-native

```javascript
// const k9o = createClient({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })  // RN, secure storage
const { data } = await k9o.functions.invoke('mistral-7b', {})
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/stream-llm-response
