Skip to main content
Glama

check_credit_balance

View your available credits for generating AI-powered music through natural language commands, enabling song creation with direct downloads.

Instructions

Check your credit balance.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'check_credit_balance' tool. It is decorated with @mcp.tool, which serves as both the implementation and registration. The function queries the MusicMCP.AI API credit endpoint, handles responses and errors, and returns formatted TextContent with the balance information.
    @mcp.tool(description="Check your credit balance.") async def check_credit_balance() -> TextContent: """Check credit balance""" try: if not api_key: raise Exception("Cannot find API key. Please set MUSICMCP_API_KEY environment variable.") url = f"{api_url}/credit" headers = {'api-key': api_key} async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client: response = await client.get(url, headers=headers) response.raise_for_status() result = response.json() # API response format: {success, message, data} if not result or not result.get("success"): error_msg = result.get("message", "Unknown error") return TextContent(type="text", text=f"❌ Credit balance check failed: {error_msg}") data = result.get("data", {}) if data.get("valid"): has_credits = data.get("hasCredits", False) credits = data.get("credits", 0) if has_credits: return TextContent( type="text", text=f"✅ API key is valid! You have {credits} credits remaining." ) else: return TextContent( type="text", text="⚠️ API key is valid but you have insufficient credits. Please recharge." ) else: return TextContent(type="text", text="❌ API key is invalid.") except Exception as e: return TextContent(type="text", text=f"❌ Failed to check credit balance: {str(e)}")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/amCharlie/aimusic-mcp-tool'

If you have feedback or need assistance with the MCP directory API, please join our Discord server