cloudbroker-sdk
v0.1.0
Published
CloudBroker SDK — Token Intelligence & Operational Financial Intelligence
Downloads
162
Maintainers
Readme
cloudbroker-sdk
Token Intelligence & Operational Financial Intelligence para Node.js.
Instalação
npm install cloudbroker-sdkUso com OpenAI
import OpenAI from "openai";
import { CloudBrokerAI } from "cloudbroker-sdk";
const openai = CloudBrokerAI.wrap(new OpenAI(), {
apiKey: "cb-key-xxxx", // sua chave CloudBroker
product: "checkout", // nome do produto
team: "mobile", // nome do squad (opcional)
});
// Todas as chamadas seguem iguais — nada muda
const res = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Olá!" }],
});Uso com Anthropic
import Anthropic from "@anthropic-ai/sdk";
import { CloudBrokerAI } from "cloudbroker-sdk";
const anthropic = CloudBrokerAI.wrap(new Anthropic(), {
apiKey: "cb-key-xxxx",
product: "checkout",
team: "mobile",
});
const res = await anthropic.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 1024,
messages: [{ role: "user", content: "Olá!" }],
});Streaming
Chamadas com stream: true também são rastreadas — o SDK observa os chunks
conforme você os consome e registra o usage ao final, sem alterar o fluxo:
const stream = await openai.chat.completions.create({
model: "gpt-4o",
stream: true,
messages: [{ role: "user", content: "Olá!" }],
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
// tokens/custo são registrados automaticamente quando o stream terminaPara OpenAI, o SDK injeta stream_options: { include_usage: true } para receber
o usage no chunk final. Para Anthropic, o usage vem dos eventos
message_start / message_delta. O objeto de stream original é preservado
(.tee(), .controller, etc.).
Rastreamento de Deploy
import { CloudBrokerAI } from "cloudbroker-sdk";
// Opção 1: Via wrapper (se você está usando OpenAI/Anthropic)
const openai = CloudBrokerAI.wrap(new OpenAI(), {
apiKey: "cb-key-xxxx",
product: "checkout",
});
openai.trackDeploy({
repo: "myapp",
branch: "main",
prTitle: "feat: add new feature",
prUrl: "https://github.com/org/myapp/pull/42",
author: "john.doe",
prNumber: 42,
filesChanged: 5,
linesAdded: 120,
linesRemoved: 30,
});
// Opção 2: Direto (sem OpenAI/Anthropic)
CloudBrokerAI.trackDeploy("cb-key-xxxx", {
repo: "myapp",
branch: "main",
prTitle: "feat: add new feature",
prUrl: "https://github.com/org/myapp/pull/42",
author: "john.doe",
prNumber: 42,
filesChanged: 5,
linesAdded: 120,
linesRemoved: 30,
});Garantias
- Fire-and-forget: se o CloudBroker estiver fora, sua aplicação não é afetada
- Zero latência adicional: o tracking acontece em background
- Retry automático: eventos com falha são reenviados em 30s
- Fila local: até 500 eventos em memória se o servidor estiver indisponível
API Key CloudBroker
Gere sua chave em app.cloudbroker.app.br → Configurações → API Keys.
