cw-ai
Installation
SKILL.md
CW Agents AI as a Service
Apps get AI through the CW Agents AI gateway: one endpoint per project, OpenAI-compatible chat plus a Decisions API, billed to the organization's monthly AI credits.
Why it runs on the app's server: the gateway key spends the organization's money. The browser calls the app, and the app calls the gateway, so the key never reaches a bundle, response or log. The server also owns models, prompts and limits, so a user can't swap in an expensive model or rewrite the instructions.
Setup
- Put the gateway in one server module,
apps/api/src/services/ai-gateway.ts(code). Its base URL is a constant:https://agents.customware.ai/api/features/ai/v1/<projectId>.- Read
projectIdfrom the Builder's raw task record at.tasks/task.json(the brief.tasks/task.mdlists it in its frontmatter) and write the real ID into the constant. - If the ID can't be determined, report that in the task outcome. A placeholder would ship an app whose AI calls all fail.
- Read
- The key is
CUSTOMWARE_AI_GATEWAY_KEYfrom the server environment. CW Agents injects it in the dev sandbox and the live app when AI as a Service is on.- If it's missing, report that AI as a Service isn't available. Never invent credentials.
- Use the Vercel AI SDK on the server:
aiwith@openrouter/ai-sdk-provider(createOpenRouter({ baseURL, apiKey })). It handles streaming, tools and schema output. Pin exact versions (chat.md).- Don't pass OpenRouter-only options (
provider,models,plugins,user,usage,transforms,extraBody). The gateway rejects unknown fields with 400, because it sets routing and billing itself.
- Don't pass OpenRouter-only options (
- Before any AI screen, set up the UI with ui.md: install AI Elements and add the safe
AiResponse. Every AI screen uses them; never fall back to plain components.