Follow these steps inside your Google AI Studio workspace:
Settings > Billing & Credits).In the billing attachment dialog:
Free-tier and paid-tier keys in Google AI Studio have distinct quota behaviors:
| API Key Tier | Rate Limits & Caps | Billing Behavior |
|---|---|---|
| Free Tier Key | 15 RPM / 1,500 RPD (subject to free capacity throttling) | $0.00 billed; stops immediately on 429 quota exhaustion |
| Paid Tier Key (Cloud Linked) | 1,000+ RPM (scalable up to enterprise levels) | Draws down promotional credits automatically; transitions to Cloud billing only after credits deplete |
Below is a production-grade TypeScript snippet using @google/genai v3.3.0 demonstrating how to configure client interactions, inspect token usage metadata, and handle model quota exhaustion gracefully:
import { GoogleGenAI } from "@google/genai";
// Initialize client with Paid-Tier API Key linked to Cloud Credits
const ai = new GoogleGenAI({
apiKey: process.env.GEMINI_PAID_API_KEY
});
async function runFrontierWorkflow(prompt: string) {
try {
console.log("[Orchestrator] Invoking Gemini 4 Carbon for deep reasoning...");
// Primary invocation: Frontier reasoning with high thinking level
const interaction = await ai.clients.interactions.create({
model: "gemini-4-carbon",
input: prompt,
config: {
thinking_config: { thinking_level: "high" },
automatic_continuation: true,
tools: [{ type: "google_search" }]
}
});
console.log("[Reasoning Complete]:", interaction.output?.text);
// Telemetry: inspect token consumption drawn against cloud credits
if (interaction.usage_metadata) {
const { prompt_token_count, candidates_token_count, total_token_count } = interaction.usage_metadata;
console.log(`[Credits Drawdown]: In: ${prompt_token_count} | Out: ${candidates_token_count} | Total: ${total_token_count}`);
}
} catch (error: any) {
// If rate limit or quota pressure occurs, gracefully fall back to Gemini 4 Hydrogen
if (error.status === 429) {
console.warn("[Quota Warning] Falling back to high-speed execution workhorse: Gemini 4 Hydrogen");
const fallbackInteraction = await ai.clients.interactions.create({
model: "gemini-4-hydrogen",
input: prompt,
config: {
thinking_config: { thinking_level: "medium" },
automatic_continuation: true
}
});
console.log("[Fallback Output]:", fallbackInteraction.output?.text);
} else {
throw error;
}
}
}
// Example usage
runFrontierWorkflow("Analyze architecture trade-offs for multi-tenant vector caching.");
To ensure peace of mind that you will never incur unexpected credit card charges once your promotional credits run out, configure a Google Cloud Budget Alert using the gcloud CLI:
# Create a $10 monthly threshold alert with 50%, 90%, and 100% notification triggers
gcloud billing budgets create \
--billing-account=YOUR_BILLING_ACCOUNT_ID \
--display-name="AI Studio Developer Guardrail" \
--budget-amount=10.00USD \
--threshold-rule=percent=0.50 \
--threshold-rule=percent=0.90 \
--threshold-rule=percent=1.00 \
--all-updates-rule-pubsub-topic="projects/YOUR_PROJECT_ID/topics/billing-alerts"