Cost controls

Set LLM cost guardrails before scaling API traffic

Use allowlists, token caps, route reviews and usage logs around https://www.tken.shop/v1 so experiments do not silently become uncontrolled production spend.

Node.js model allowlist
const allowedModels = new Set(
  process.env.TKEN_ALLOWED_MODELS.split(",").map(value => value.trim())
);

function assertAllowedModel(model) {
  if (!allowedModels.has(model)) {
    throw new Error(`Model is not approved for this workflow: ${model}`);
  }
}

const model = process.env.TKEN_CHAT_MODEL;
assertAllowedModel(model);

await client.chat.completions.create({
  model,
  max_tokens: 300,
  messages: [{ role: "user", content: "Answer briefly." }]
});
Cap output tokens per workflow
Review model routes before scaling
Track usage without storing secrets

Usage log shape

Store operational metadata that helps control spend, but avoid keeping raw prompts, customer secrets, authorization headers or private documents in routine logs.

Safe metadata example record
{
  "workflow": "support_summary",
  "model": "approved-model-id",
  "base_url": "https://www.tken.shop/v1",
  "status": 200,
  "latency_ms": 1840,
  "prompt_tokens": 420,
  "completion_tokens": 96,
  "fallback_used": false
}

Cost guardrail checklist

1. Define approved routes

Keep a short model allowlist per workflow and require review before adding a more expensive or experimental route.

2. Cap request size

Limit max output tokens, trim repeated context and reject inputs that exceed the workflow's expected size.

3. Review usage before raising traffic

Check error rate, fallback rate, token usage and live pricing before moving from tests to larger production batches.

Disclosure: TKEN is an independent third-party API gateway. Use the live pricing and account views for current model availability and cost before scaling.

Start with measured traffic

Route small tests through https://www.tken.shop/v1, review usage, then raise limits only after the economics are clear.