check-api-status
Verify API connectivity and validate API keys to ensure proper access to Orshot's image generation services.
Instructions
Check the API connectivity and validate the API key
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | No | Orshot API key for authentication (optional if set in environment) |
Implementation Reference
- src/index.ts:1435-1541 (registration)Registration of the 'check-api-status' tool using server.tool, including the name, description, input schema, and handler function.
server.tool( "check-api-status", "Check the API connectivity and validate the API key", { apiKey: z.string().optional().describe("Orshot API key for authentication (optional if set in environment)"), }, async (args) => { const { apiKey } = args; const actualApiKey = apiKey || DEFAULT_API_KEY; if (!actualApiKey) { return { content: [ { type: "text", text: "ā No API key provided. Please provide an API key parameter or set ORSHOT_API_KEY environment variable.", }, ], }; } try { // Test API connectivity with a simple endpoint const response = await fetch(`${ORSHOT_API_BASE}/v1/templates`, { method: "GET", headers: { "Authorization": `Bearer ${actualApiKey}`, "Content-Type": "application/json", }, }); const statusCode = response.status; const statusText = response.statusText; if (response.ok) { const data = await response.json(); const templateCount = Array.isArray(data) ? data.length : 0; return { content: [ { type: "text", text: `ā API Status: Connected successfully! š API Key: Valid š Status Code: ${statusCode} ${statusText} š Templates Found: ${templateCount} š API Base URL: ${ORSHOT_API_BASE} Your Orshot API integration is working correctly.`, }, ], }; } else { let errorMessage = `HTTP ${statusCode} ${statusText}`; try { const errorData = await response.text(); const parsedError = JSON.parse(errorData); if (parsedError.message) { errorMessage = parsedError.message; } else if (parsedError.error) { errorMessage = parsedError.error; } } catch { // If we can't parse the error, use the raw response } return { content: [ { type: "text", text: `ā API Status: Connection failed š API Key: ${statusCode === 401 ? 'Invalid or expired' : 'Potentially valid'} š Status Code: ${statusCode} ${statusText} š API Base URL: ${ORSHOT_API_BASE} ā Error: ${errorMessage} ${statusCode === 401 ? 'Please check your API key.' : statusCode === 403 ? 'API key valid but insufficient permissions.' : statusCode === 404 ? 'API endpoint not found.' : statusCode >= 500 ? 'Orshot server error. Try again later.' : 'Unknown error occurred.'}`, }, ], }; } } catch (error) { return { content: [ { type: "text", text: `ā API Status: Network error š API Base URL: ${ORSHOT_API_BASE} ā Error: ${error instanceof Error ? error.message : 'Unknown network error'} This could be due to: - Network connectivity issues - Firewall blocking the request - DNS resolution problems - Orshot service unavailable`, }, ], }; } } ); - src/index.ts:1441-1540 (handler)Handler function that performs the actual tool logic: validates API key presence, makes a GET request to Orshot API /v1/templates endpoint to test connectivity and authentication, and returns a formatted status report including success/failure details.
async (args) => { const { apiKey } = args; const actualApiKey = apiKey || DEFAULT_API_KEY; if (!actualApiKey) { return { content: [ { type: "text", text: "ā No API key provided. Please provide an API key parameter or set ORSHOT_API_KEY environment variable.", }, ], }; } try { // Test API connectivity with a simple endpoint const response = await fetch(`${ORSHOT_API_BASE}/v1/templates`, { method: "GET", headers: { "Authorization": `Bearer ${actualApiKey}`, "Content-Type": "application/json", }, }); const statusCode = response.status; const statusText = response.statusText; if (response.ok) { const data = await response.json(); const templateCount = Array.isArray(data) ? data.length : 0; return { content: [ { type: "text", text: `ā API Status: Connected successfully! š API Key: Valid š Status Code: ${statusCode} ${statusText} š Templates Found: ${templateCount} š API Base URL: ${ORSHOT_API_BASE} Your Orshot API integration is working correctly.`, }, ], }; } else { let errorMessage = `HTTP ${statusCode} ${statusText}`; try { const errorData = await response.text(); const parsedError = JSON.parse(errorData); if (parsedError.message) { errorMessage = parsedError.message; } else if (parsedError.error) { errorMessage = parsedError.error; } } catch { // If we can't parse the error, use the raw response } return { content: [ { type: "text", text: `ā API Status: Connection failed š API Key: ${statusCode === 401 ? 'Invalid or expired' : 'Potentially valid'} š Status Code: ${statusCode} ${statusText} š API Base URL: ${ORSHOT_API_BASE} ā Error: ${errorMessage} ${statusCode === 401 ? 'Please check your API key.' : statusCode === 403 ? 'API key valid but insufficient permissions.' : statusCode === 404 ? 'API endpoint not found.' : statusCode >= 500 ? 'Orshot server error. Try again later.' : 'Unknown error occurred.'}`, }, ], }; } } catch (error) { return { content: [ { type: "text", text: `ā API Status: Network error š API Base URL: ${ORSHOT_API_BASE} ā Error: ${error instanceof Error ? error.message : 'Unknown network error'} This could be due to: - Network connectivity issues - Firewall blocking the request - DNS resolution problems - Orshot service unavailable`, }, ], }; } } - src/index.ts:1439-1440 (schema)Input schema using Zod: optional apiKey string parameter.
apiKey: z.string().optional().describe("Orshot API key for authentication (optional if set in environment)"), },