AgenticPacks
Product

Chat and credits

Learn how streaming chat spends credits, and what happens when the wallet is empty.

Chat is a streaming reply from the AI SDK. The screen is useChat on the client. The server maps the SDK's inputTokens and outputTokens into the app's prompt and completion counts, then deducts credits from Postgres.

This page covers which model answers, how credits are counted, and the cases where the route refuses the call.

Model

OSS uses one model, gpt-5-mini. There is no mock stream. A missing OPENAI_API_KEY makes POST /api/chat return 400 before any tokens are generated.

Credits

A finished reply costs Math.max(1, Math.ceil(totalTokens / 1000)) credits. The deduction and the usage row are written in Postgres. The balance is then read back through /api/user/profile, and the sidebar hears a credits-updated event.

An empty wallet returns 402, and OpenAI is not called. If the conversation row cannot be saved, the route returns 503. A failure while reading the balance can surface as 500 with DATABASE_ERROR.

CHAT_MAX_TOKENS caps the completion. The default is 4096. Stopping the generation uses useChat().stop() and aborts with the request signal.

Models

Pro routes across OpenAI, Anthropic, and Google. The selector hides a provider whose key is empty. When the selected provider has no key, the service returns a local mock stream so the screen can still be demonstrated.

That fallback does not apply to file search. Embeddings still require OPENAI_API_KEY, which is covered in Knowledge.

Credits

Personal chat spends the signed-in user's balance. Chat inside a team workspace spends the team owner's shared pool. The dashboard stream at GET /api/dashboard/stream pushes the current balance, so the number updates without a reload.

A reply that the user stops is only deducted when the stream actually finishes.

Where to go next

Team pools are covered in Teams. Document search, which is Pro only, is covered in Knowledge.