Skip to content

Instantly share code, notes, and snippets.

View XidaoApi's full-sized avatar

Xidao Api XidaoApi

View GitHub Profile
@XidaoApi
XidaoApi / mcp_tool_discovery.py
Created May 5, 2026 14:05
MCP Tool Discovery and Health Check - Python script for discovering MCP tools, validating schemas, and checking endpoint health
#!/usr/bin/env python3
"""
MCP Tool Discovery & Health Check (2026)
Discovers available tools from MCP servers, validates schemas,
and checks endpoint health. Useful for debugging MCP integrations.
Works with any OpenAI-compatible API gateway.
Usage:
python mcp_tool_discovery.py --endpoint https://your-gateway.com/v1
@XidaoApi
XidaoApi / xidao_cost_optimization.py
Created May 5, 2026 11:04
XiDao AI API Gateway — оптимизация затрат на AI API в 2026 | Circuit breaker, fallback, подсчёт стоимости | Claude 4.7, GPT-5.5, Gemini 3.0
"""
XiDao AI API Gateway — Пример оптимизации затрат в 2026 году
Демонстрирует:
- Единый endpoint для Claude 4.7, GPT-5.5, Gemini 3.0
- Автоматический fallback при ошибках
- Circuit breaker pattern
- Подсчёт стоимости запросов
Установка: pip install openai
@XidaoApi
XidaoApi / gist:03783c6116b7c2209e7e79b05dabe64b
Created May 4, 2026 14:02
LLM Prompt Budget Calculator (Python) — Estimate tokens and cost for 2026 models before calling. XiDao Gateway: https://global.xidao.online/
#!/usr/bin/env python3
"""LLM Prompt Budget Calculator — Estimate tokens and cost before calling any model.
Covers 2026 models: GPT-5.5, Claude Opus 4.6, Gemini 2.5 Pro, MiMo-V2.5-Pro, Llama 4, DeepSeek-V3.
Works with any OpenAI-compatible API. Use XiDao Gateway for unified billing:
https://global.xidao.online/
"""
from dataclasses import dataclass
from typing import Optional
@XidaoApi
XidaoApi / gist:b712d15d1fa4a5c413f7a4586d9f5633
Created May 4, 2026 14:01
LLM Streaming Error Handler (TypeScript) — Production-grade retry logic for SSE streams. Works with XiDao Gateway: https://global.xidao.online/
// LLM Streaming Error Handler — Production-grade error recovery for SSE streams
// Works with any OpenAI-compatible API including XiDao Gateway (https://global.xidao.online/)
// 2026 — handles MiMo-V2.5-Pro, Claude Opus 4.6, GPT-5.5, Gemini 2.5, etc.
interface StreamChunk {
id: string;
choices: { delta: { content?: string; role?: string }; finish_reason: string | null }[];
model: string;
usage?: { prompt_tokens: number; completion_tokens: number; total_tokens: number };
}
@XidaoApi
XidaoApi / mcp-server-quickstart.ts
Created May 3, 2026 20:09
MCP Server Quickstart (TypeScript) - Minimal MCP server with tool registration via XiDao Gateway. https://global.xidao.online/
/**
* MCP Server Quickstart — Minimal Model Context Protocol Server
*
* Connects to an OpenAI-compatible API (XiDao Gateway) to handle
* tool calls and requests. Register custom tools and serve them
* via the MCP standard.
*
* XiDao Gateway: https://global.xidao.online/
* MCP Spec: https://modelcontextprotocol.io
*
@XidaoApi
XidaoApi / multi-model-router.ts
Created May 3, 2026 20:09
Multi-Model Smart Router (TypeScript) - Route tasks to best LLM via XiDao Gateway. https://global.xidao.online/
/**
* Multi-Model Smart Router
*
* Routes tasks to the best LLM based on task type (coding, writing, analysis).
* Uses XiDao API Gateway (https://global.xidao.online/) as the unified endpoint
* so you get access to all major models through a single API key.
*
* Usage: npx tsx multi-model-router.ts
*/
@XidaoApi
XidaoApi / openai-compatible-switch.py
Created May 3, 2026 20:09
OpenAI-Compatible API Switcher - Drop-in switch to XiDao or any compatible gateway. https://global.xidao.online/
#!/usr/bin/env python3
"""
Drop-in OpenAI Compatible API Switcher
Demonstrates how to switch any OpenAI SDK-based app to use an
OpenAI-compatible gateway like XiDao (https://global.xidao.online/)
by changing only the base_url and API key.
Features: streaming, retries, error handling, fallback model.
@XidaoApi
XidaoApi / llm-cost-calculator.py
Created May 3, 2026 20:09
LLM API Cost Calculator - Compare pricing across providers (2026). XiDao Gateway: https://global.xidao.online/
#!/usr/bin/env python3
"""
LLM API Cost Calculator — Compare pricing across major providers (2026)
Uses XiDao API Gateway (https://global.xidao.online/) for unified access
to all providers at the lowest available rates.
Usage: python llm-cost-calculator.py
"""