[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M752ERWAFJ2YGENZZKJ1NNMA":3,"skill-same:01M752ERWAFJ2YGENZZKJ1NNMA":49},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":29,"commitSha":30,"skillDirectory":5,"forksCount":14,"repositoryHtmlUrl":31,"repositoryHomepageUrl":6,"ownerHtmlUrl":32,"ownerBlogUrl":33,"ownerDescription":6,"updatedAt":34,"install":35,"resources":48},"01M752ERWAFJ2YGENZZKJ1NNMA","langchain-rate-limits",null,"Implement LangChain rate limiting and backoff strategies.\nUse when handling API quotas, implementing retry logic,\nor optimizing request throughput for LLM providers.\nTrigger with phrases like \"langchain rate limit\", \"langchain throttling\",\n\"langchain backoff\", \"langchain retry\", \"API quota\".","SamuelChien\u002Fmega-skills-collection","SamuelChien","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F4652114?v=4","01M74KK34WVHA0P5ZYSJRDDFMG","Samuel Chien","01M74KK35FQN1N9VZ9EPTH3P2S",0,"MIT","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Flangchain-rate-limits\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: langchain-rate-limits\ndescription: |\n  Implement LangChain rate limiting and backoff strategies.\n  Use when handling API quotas, implementing retry logic,\n  or optimizing request throughput for LLM providers.\n  Trigger with phrases like \"langchain rate limit\", \"langchain throttling\",\n  \"langchain backoff\", \"langchain retry\", \"API quota\".\nallowed-tools: Read, Write, Edit\nversion: 1.0.0\nlicense: MIT\nauthor: Jeremy Longshore \u003Cjeremy@intentsolutions.io>\ncompatible-with: claude-code, codex, openclaw\n---\n# LangChain Rate Limits\n\n## Overview\nImplement robust rate limiting and retry strategies for LangChain applications to handle API quotas gracefully.\n\n## Prerequisites\n- LangChain installed with LLM provider\n- Understanding of provider rate limits\n- tenacity package for advanced retry logic\n\n## Instructions\n\n### Step 1: Understand Provider Limits\n```python\n# Common rate limits by provider:\nRATE_LIMITS = {\n    \"openai\": {\n        \"gpt-4o\": {\"rpm\": 10000, \"tpm\": 800000},  # 800000: 10000: 10 seconds in ms\n        \"gpt-4o-mini\": {\"rpm\": 10000, \"tpm\": 4000000},  # 4000000: 10 seconds in ms\n    },\n    \"anthropic\": {\n        \"claude-3-5-sonnet\": {\"rpm\": 4000, \"tpm\": 400000},  # 400000: 4000: dev server port\n    },\n    \"google\": {\n        \"gemini-1.5-pro\": {\"rpm\": 360, \"tpm\": 4000000},  # 360 = configured value\n    }\n}\n# rpm = requests per minute, tpm = tokens per minute\n```\n\n### Step 2: Built-in Retry Configuration\n```python\nfrom langchain_openai import ChatOpenAI\n\n# LangChain has built-in retry with exponential backoff\nllm = ChatOpenAI(\n    model=\"gpt-4o-mini\",\n    max_retries=3,  # Number of retries\n    request_timeout=30,  # Timeout per request\n)\n```\n\n### Step 3: Advanced Retry with Tenacity\n```python\nfrom tenacity import (\n    retry,\n    stop_after_attempt,\n    wait_exponential,\n    retry_if_exception_type\n)\nfrom openai import RateLimitError, APIError\n\n@retry(\n    stop=stop_after_attempt(5),\n    wait=wait_exponential(multiplier=1, min=4, max=60),\n    retry=retry_if_exception_type((RateLimitError, APIError))\n)\ndef call_with_retry(chain, input_data):\n    \"\"\"Call chain with exponential backoff.\"\"\"\n    return chain.invoke(input_data)\n\n# Usage\nresult = call_with_retry(chain, {\"input\": \"Hello\"})\n```\n\n### Step 4: Rate Limiter Wrapper\n```python\nimport asyncio\nimport time\nfrom collections import deque\nfrom threading import Lock\n\nclass RateLimiter:\n    \"\"\"Token bucket rate limiter for API calls.\"\"\"\n\n    def __init__(self, requests_per_minute: int = 60):\n        self.rpm = requests_per_minute\n        self.interval = 60.0 \u002F requests_per_minute\n        self.timestamps = deque()\n        self.lock = Lock()\n\n    def acquire(self):\n        \"\"\"Block until request can be made.\"\"\"\n        with self.lock:\n            now = time.time()\n            # Remove timestamps older than 1 minute\n            while self.timestamps and now - self.timestamps[0] > 60:\n                self.timestamps.popleft()\n\n            if len(self.timestamps) >= self.rpm:\n                sleep_time = 60 - (now - self.timestamps[0])\n                if sleep_time > 0:\n                    time.sleep(sleep_time)\n\n            self.timestamps.append(time.time())\n\n# Usage with LangChain\nrate_limiter = RateLimiter(requests_per_minute=100)\n\ndef rate_limited_call(chain, input_data):\n    rate_limiter.acquire()\n    return chain.invoke(input_data)\n```\n\n### Step 5: Async Rate Limiting\n```python\nimport asyncio\nfrom asyncio import Semaphore\n\nclass AsyncRateLimiter:\n    \"\"\"Async rate limiter with semaphore.\"\"\"\n\n    def __init__(self, max_concurrent: int = 10):\n        self.semaphore = Semaphore(max_concurrent)\n\n    async def call(self, chain, input_data):\n        async with self.semaphore:\n            return await chain.ainvoke(input_data)\n\n# Batch processing with rate limiting\nasync def process_batch(chain, inputs: list, max_concurrent: int = 5):\n    limiter = AsyncRateLimiter(max_concurrent)\n    tasks = [limiter.call(chain, inp) for inp in inputs]\n    return await asyncio.gather(*tasks, return_exceptions=True)\n```\n\n## Output\n- Configured retry logic with exponential backoff\n- Rate limiter class for request throttling\n- Async batch processing with concurrency control\n- Graceful handling of rate limit errors\n\n## Examples\n\n### Handling Rate Limits in Production\n```python\nfrom langchain_openai import ChatOpenAI\nfrom langchain_core.runnables import RunnableConfig\n\nllm = ChatOpenAI(\n    model=\"gpt-4o-mini\",\n    max_retries=5,\n)\n\n# Use batch with max_concurrency\ninputs = [{\"input\": f\"Query {i}\"} for i in range(100)]\n\nresults = chain.batch(\n    inputs,\n    config=RunnableConfig(max_concurrency=10)  # Limit concurrent calls\n)\n```\n\n### Fallback on Rate Limit\n```python\nfrom langchain_openai import ChatOpenAI\nfrom langchain_anthropic import ChatAnthropic\n\nprimary = ChatOpenAI(model=\"gpt-4o-mini\", max_retries=2)\nfallback = ChatAnthropic(model=\"claude-3-5-sonnet-20241022\")  # 20241022 = date\u002Fversion stamp\n\n# Automatically switch to fallback on rate limit\nrobust_llm = primary.with_fallbacks([fallback])\n```\n\n## Error Handling\n| Error | Cause | Solution |\n|-------|-------|----------|\n| RateLimitError | Exceeded quota | Implement backoff, reduce concurrency |\n| Timeout | Request too slow | Increase timeout, check network |\n| 429 Too Many Requests | API throttled | Wait and retry with backoff |\n| Quota Exceeded | Monthly limit hit | Upgrade plan or switch provider |\n\n## Resources\n- [OpenAI Rate Limits](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Frate-limits)\n- [Anthropic Rate Limits](https:\u002F\u002Fdocs.anthropic.com\u002Fen\u002Fapi\u002Frate-limits)\n- [tenacity Documentation](https:\u002F\u002Ftenacity.readthedocs.io\u002F)\n\n## Next Steps\nProceed to `langchain-security-basics` for security best practices.","# LangChain Rate Limits\n\n## Overview\nImplement robust rate limiting and retry strategies for LangChain applications to handle API quotas gracefully.\n\n## Prerequisites\n- LangChain installed with LLM provider\n- Understanding of provider rate limits\n- tenacity package for advanced retry logic\n\n## Instructions\n\n### Step 1: Understand Provider Limits\n```python\n# Common rate limits by provider:\nRATE_LIMITS = {\n    \"openai\": {\n        \"gpt-4o\": {\"rpm\": 10000, \"tpm\": 800000},  # 800000: 10000: 10 seconds in ms\n        \"gpt-4o-mini\": {\"rpm\": 10000, \"tpm\": 4000000},  # 4000000: 10 seconds in ms\n    },\n    \"anthropic\": {\n        \"claude-3-5-sonnet\": {\"rpm\": 4000, \"tpm\": 400000},  # 400000: 4000: dev server port\n    },\n    \"google\": {\n        \"gemini-1.5-pro\": {\"rpm\": 360, \"tpm\": 4000000},  # 360 = configured value\n    }\n}\n# rpm = requests per minute, tpm = tokens per minute\n```\n\n### Step 2: Built-in Retry Configuration\n```python\nfrom langchain_openai import ChatOpenAI\n\n# LangChain has built-in retry with exponential backoff\nllm = ChatOpenAI(\n    model=\"gpt-4o-mini\",\n    max_retries=3,  # Number of retries\n    request_timeout=30,  # Timeout per request\n)\n```\n\n### Step 3: Advanced Retry with Tenacity\n```python\nfrom tenacity import (\n    retry,\n    stop_after_attempt,\n    wait_exponential,\n    retry_if_exception_type\n)\nfrom openai import RateLimitError, APIError\n\n@retry(\n    stop=stop_after_attempt(5),\n    wait=wait_exponential(multiplier=1, min=4, max=60),\n    retry=retry_if_exception_type((RateLimitError, APIError))\n)\ndef call_with_retry(chain, input_data):\n    \"\"\"Call chain with exponential backoff.\"\"\"\n    return chain.invoke(input_data)\n\n# Usage\nresult = call_with_retry(chain, {\"input\": \"Hello\"})\n```\n\n### Step 4: Rate Limiter Wrapper\n```python\nimport asyncio\nimport time\nfrom collections import deque\nfrom threading import Lock\n\nclass RateLimiter:\n    \"\"\"Token bucket rate limiter for API calls.\"\"\"\n\n    def __init__(self, requests_per_minute: int = 60):\n        self.rpm = requests_per_minute\n        self.interval = 60.0 \u002F requests_per_minute\n        self.timestamps = deque()\n        self.lock = Lock()\n\n    def acquire(self):\n        \"\"\"Block until request can be made.\"\"\"\n        with self.lock:\n            now = time.time()\n            # Remove timestamps older than 1 minute\n            while self.timestamps and now - self.timestamps[0] > 60:\n                self.timestamps.popleft()\n\n            if len(self.timestamps) >= self.rpm:\n                sleep_time = 60 - (now - self.timestamps[0])\n                if sleep_time > 0:\n                    time.sleep(sleep_time)\n\n            self.timestamps.append(time.time())\n\n# Usage with LangChain\nrate_limiter = RateLimiter(requests_per_minute=100)\n\ndef rate_limited_call(chain, input_data):\n    rate_limiter.acquire()\n    return chain.invoke(input_data)\n```\n\n### Step 5: Async Rate Limiting\n```python\nimport asyncio\nfrom asyncio import Semaphore\n\nclass AsyncRateLimiter:\n    \"\"\"Async rate limiter with semaphore.\"\"\"\n\n    def __init__(self, max_concurrent: int = 10):\n        self.semaphore = Semaphore(max_concurrent)\n\n    async def call(self, chain, input_data):\n        async with self.semaphore:\n            return await chain.ainvoke(input_data)\n\n# Batch processing with rate limiting\nasync def process_batch(chain, inputs: list, max_concurrent: int = 5):\n    limiter = AsyncRateLimiter(max_concurrent)\n    tasks = [limiter.call(chain, inp) for inp in inputs]\n    return await asyncio.gather(*tasks, return_exceptions=True)\n```\n\n## Output\n- Configured retry logic with exponential backoff\n- Rate limiter class for request throttling\n- Async batch processing with concurrency control\n- Graceful handling of rate limit errors\n\n## Examples\n\n### Handling Rate Limits in Production\n```python\nfrom langchain_openai import ChatOpenAI\nfrom langchain_core.runnables import RunnableConfig\n\nllm = ChatOpenAI(\n    model=\"gpt-4o-mini\",\n    max_retries=5,\n)\n\n# Use batch with max_concurrency\ninputs = [{\"input\": f\"Query {i}\"} for i in range(100)]\n\nresults = chain.batch(\n    inputs,\n    config=RunnableConfig(max_concurrency=10)  # Limit concurrent calls\n)\n```\n\n### Fallback on Rate Limit\n```python\nfrom langchain_openai import ChatOpenAI\nfrom langchain_anthropic import ChatAnthropic\n\nprimary = ChatOpenAI(model=\"gpt-4o-mini\", max_retries=2)\nfallback = ChatAnthropic(model=\"claude-3-5-sonnet-20241022\")  # 20241022 = date\u002Fversion stamp\n\n# Automatically switch to fallback on rate limit\nrobust_llm = primary.with_fallbacks([fallback])\n```\n\n## Error Handling\n| Error | Cause | Solution |\n|-------|-------|----------|\n| RateLimitError | Exceeded quota | Implement backoff, reduce concurrency |\n| Timeout | Request too slow | Increase timeout, check network |\n| 429 Too Many Requests | API throttled | Wait and retry with backoff |\n| Quota Exceeded | Monthly limit hit | Upgrade plan or switch provider |\n\n## Resources\n- [OpenAI Rate Limits](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Frate-limits)\n- [Anthropic Rate Limits](https:\u002F\u002Fdocs.anthropic.com\u002Fen\u002Fapi\u002Frate-limits)\n- [tenacity Documentation](https:\u002F\u002Ftenacity.readthedocs.io\u002F)\n\n## Next Steps\nProceed to `langchain-security-basics` for security best practices.",{"name":5,"author":24,"license":15,"version":25,"description":26,"allowed-tools":27,"compatible-with":28},"Jeremy Longshore \u003Cjeremy@intentsolutions.io>","1.0.0","Implement LangChain rate limiting and backoff strategies.\nUse when handling API quotas, implementing retry logic,\nor optimizing request throughput for LLM providers.\nTrigger with phrases like \"langchain rate limit\", \"langchain throttling\",\n\"langchain backoff\", \"langchain retry\", \"API quota\".\n","Read, Write, Edit","claude-code, codex, openclaw","main","c2b1fdccc779e99ac814e55fb69ca8d71215dd0f","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection","https:\u002F\u002Fgithub.com\u002FSamuelChien","http:\u002F\u002Fsamuelchien.com\u002F","2026-05-26 08:27:14",{"source":8,"skillName":5,"commands":36,"prompt":46,"zipAvailable":47},[37,40,43],{"tool":38,"command":39},"npx","npx skills add SamuelChien\u002Fmega-skills-collection --skill langchain-rate-limits",{"tool":41,"command":42},"bunx","bunx skills add SamuelChien\u002Fmega-skills-collection --skill langchain-rate-limits",{"tool":44,"command":45},"pnpm","pnpm dlx skills add SamuelChien\u002Fmega-skills-collection --skill langchain-rate-limits","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Flangchain-rate-limits\u002FSKILL.md",true,[],[50,57,64,71,78,86],{"skillNo":51,"name":52,"nameZh":6,"description":53,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":19},"01M76R4WZQZAXGGXMQCA0FZ716","zustand-store-ts","Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state\u002Faction separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-ts\u002FSKILL.md",[],[],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M76R4T9KENDH7FENGZQHBW4G","zustand-store-creator","Zustand Store Creator - Auto-activating skill for Frontend Development.\nTriggers on: zustand store creator, zustand store creator\nPart of the Frontend Development skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-creator\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M76R3YWN84B7SANJ52X799ZE","zero-trust-config-helper","Zero Trust Config Helper - Auto-activating skill for Security Advanced.\nTriggers on: zero trust config helper, zero trust config helper\nPart of the Security Advanced skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzero-trust-config-helper\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M76R3HNSV2AEYSKHM915GJ58","zapier-integration-helper","Zapier Integration Helper - Auto-activating skill for Business Automation.\nTriggers on: zapier integration helper, zapier integration helper\nPart of the Business Automation skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzapier-integration-helper\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":82,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":19},"01M76R3DJSKAT4FA7DV4BF3GCE","zai-cli","Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP.\nUse when user needs image\u002Fvideo analysis, OCR, UI-to-code conversion, error diagnosis,\nreal-time web search, web page to markdown extraction, or GitHub code exploration.\nTrigger with phrases like \"analyze this image\", \"search the web for\", \"read this page\",\n\"explore this repo\", or \"use zai\". Requires Z_AI_API_KEY.","Apache-2.0","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzai-cli\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":19},"01M76R2KAM699XE9AJVAWE4H2E","yt-research","Research competitor YouTube channels, niches, and trending topics for your content strategy.\nUse this skill whenever the user says \"research channels\", \"analyze competitors\", \"find trending topics\",\n\"niche analysis\", \"competitive research\", \"what are other creators doing\", \"scrape YouTube channels\",\nor wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fyt-research\u002FSKILL.md",[],[]]