| name | castai-sdk-patterns |
| description | Production-ready CAST AI REST API wrapper patterns in TypeScript and Python.
Use when building reusable CAST AI clients, implementing retry logic,
or wrapping the CAST AI API for team use.
Trigger with phrases like "cast ai API patterns", "cast ai client wrapper",
"cast ai TypeScript", "cast ai Python client".
|
| allowed-tools | Read, Write, Edit |
| version | 1.4.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","kubernetes","cost-optimization","castai"] |
| compatibility | Designed for Claude Code |
CAST AI SDK Patterns
Overview
CAST AI uses a REST API with X-API-Key header authentication. There is no official SDK -- build typed wrappers around fetch or requests. These patterns cover singleton clients, typed responses, retry with backoff, and multi-cluster management.
Prerequisites
- Completed
castai-install-auth setup
- TypeScript 5+ or Python 3.10+
- Familiarity with async/await patterns
Instructions
Step 1: TypeScript API Client
interface CastAIConfig {
apiKey: string;
baseUrl?: string;
timeoutMs?: number;
}
interface CastAICluster {
id: string;
name: string;
status: string;
providerType: "eks" | "gke" | "aks";
agentStatus: string;
createdAt: string;
}
interface CastAISavings {
monthlySavings: number;
savingsPercentage: number;
currentMonthlyCost: number;
optimizedMonthlyCost: number;
}
interface CastAINode {
name: string;
instanceType: ;
: | ;
: ;
: ;
: ;
}
{
: ;
: ;
: ;
() {
. = config.;
. = config. ?? ;
. = config. ?? ;
}
request<T>(: , ?: ): <T> {
controller = ();
timeout = ( controller.(), .);
{
response = (, {
...options,
: {
: .,
: ,
...options?.,
},
: controller.,
});
(!response.) {
body = response.();
(response., body, path);
}
response.();
} {
(timeout);
}
}
(): <[]> {
data = .<{ : [] }>(
);
data.;
}
(: ): <> {
.();
}
(: ): <[]> {
data = .<{ : [] }>(
);
data.;
}
(: , : <, >): <> {
.(, {
: ,
: .(policies),
});
}
}
{
() {
();
. = ;
}
(): {
. === || . >= ;
}
}