Integrating these prompts into your workflow is simple. Copy the entire markdown prompt for your chosen language and provide it as context to your AI assistant.
For Chat Interfaces (Claude, ChatGPT, etc.): Paste the prompt at the beginning of your conversation before asking the AI to write code.
For Cursor IDE: Add the prompt to your projectβs Rules to enforce the guidelines across all AI interactions.
For GitHub Copilot: Save the prompt to a file (e.g. coingecko_rules.md) and reference it in your chat with @workspace #coingecko_rules.md.
For Claude Code: Include the prompt in your CLAUDE.md file.
# Goal: Generate Python code for the CoinGecko API using ONLY the official `coingecko_sdk`.## π¨ Critical Rules1. **SDK Exclusivity**: - **ALWAYS** use the official `coingecko_sdk` package. - **NEVER** use the old `pycoingecko` library or make direct HTTP requests with `requests`, `httpx`, or `urllib`.2. **Authentication**: - **ALWAYS** load the API key from environment variables (e.g., `os.environ.get("COINGECKO_PRO_API_KEY")`). - **NEVER** hardcode API keys or any other credentials in the source code.3. **Client Implementation**: - **ALWAYS** initialize a single, reusable client instance (`Coingecko` or `AsyncCoingecko`) for the application. - **ALWAYS** configure automatic retries by setting the `max_retries` parameter on the client. - **NEVER** implement manual retry loops using `time.sleep()`. The SDK handles this internally.4. **Error Handling**: - **ALWAYS** catch specific SDK exceptions (e.g., `coingecko_sdk.RateLimitError`, `coingecko_sdk.NotFoundError`). - **NEVER** use a generic `except Exception:` block to catch known API errors.## β Correct Implementation ExampleThis is the standard for all generated code.```python# src/api/client.pyimport osfrom coingecko_sdk import Coingecko, AsyncCoingecko# Initialize a single, reusable client. This should be imported and used application-wide.client = Coingecko( pro_api_key=os.environ.get("COINGECKO_PRO_API_KEY"), environment="pro", max_retries=3, # Rely on the SDK's built-in retry mechanism.)# Optional: Initialize a single async client for concurrent applications.async_client = AsyncCoingecko( pro_api_key=os.environ.get("COINGECKO_PRO_API_KEY"), environment="pro", max_retries=3,)# src/main.pyfrom api.client import clientfrom coingecko_sdk import RateLimitError, APIErrordef get_bitcoin_price(): try: price_data = client.simple.price.get( ids="bitcoin", vs_currencies="usd", ) # Access data using Pydantic models or dictionary keys return price_data['bitcoin'].usd except RateLimitError: print("Rate limit exceeded. Please try again later.") return None except APIError as e: print(f"An API error occurred: {e}") return Noneif __name__ == "__main__": price = get_bitcoin_price() if price: print(f"The current price of Bitcoin is: ${price}")```## β Deprecated Patterns to AVOIDYou **MUST NOT** generate code that includes any of the following outdated patterns.```python# β NO direct HTTP requests.import requestsresponse = requests.get('[https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd](https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd)')# β NO use of the outdated `pycoingecko` library.from pycoingecko import CoinGeckoAPIcg = CoinGeckoAPI()# β NO hardcoded API keys.client = Coingecko(pro_api_key='CG-abc123xyz789')# β NO manual retry loops. The SDK's `max_retries` handles this.import timefor i in range(3): try: data = client.simple.price.get(ids='bitcoin', vs_currencies='usd') break except: time.sleep(5)# β NO generic exception handling for API errors.try: data = client.simple.price.get(ids='bitcoin', vs_currencies='usd')except Exception as e: print(f"An error occurred: {e}")```## π Final CheckBefore providing a response, you **MUST** verify that your generated code:1. Imports and uses `coingecko_sdk`.2. Loads the API key from environment variables.3. Follows all other Critical Rules.4. Does **NOT** contain any Deprecated Patterns.
Notice something off or missing? Let us know by opening an Issue here.Have feedback, a cool idea, or need help? Reach out to soonaik@coingecko[dot]com.