Python
CGPT SDK Docs
ChainGPT AI News Generator SDK Documentation
The ChainGPT AI News Generator provides access to curated blockchain and cryptocurrency news with advanced filtering capabilities. You can retrieve the latest news articles, filter by categories, tokens, and search terms, and implement pagination for large datasets.
Table of Contents
Installation
Quick Start
Initialization and Setup
NewsService API Reference
Data Models Reference
Usage Examples
Error Handling
Common Category and Token IDs
Best Practices
Installation
Install the ChainGPT SDK via pip:
Or add to your requirements.txt:
For environment variable management (recommended):
Quick Start
Initialization and Setup
Environment Variables
Set up your API key as an environment variable for security:
Or use a .env file:
Basic Client Setup
NewsService API Reference
get_news() Method
get_news() MethodRetrieves AI-generated news articles with comprehensive filtering and pagination capabilities.
Method Signature
Parameters
category_id
Optional[Union[int, List[int]]]
None
Filter by one or more category IDs. Examples: 8 (NFT), [8, 12] (multiple categories)
sub_category_id
Optional[Union[int, List[int]]]
None
Filter by one or more sub-category IDs. Examples: 15 (Ethereum), [15, 39] (multiple)
token_id
Optional[Union[int, List[int]]]
None
Filter by specific token IDs. Examples: 79 (Bitcoin), [79, 1027] (multiple tokens)
search_query
Optional[str]
None
Keyword search for title/description. Examples: "halving", "defi", "nft"
fetch_after
Optional[str]
None
Date filter in YYYY-MM-DD format. Only returns articles published after this date
limit
Optional[int]
10
Maximum articles to return (pagination). Range: 1-100
offset
Optional[int]
0
Number of articles to skip (pagination)
sort_by
Optional[str]
"createdAt"
Sort field. Currently supports "createdAt"
Return Value
Returns a GetNewsResponseModel object containing:
statusCode
Optional[int]
HTTP status code (200 for success)
message
Optional[str]
Response message
data
List[NewsArticleModel]
Array of news articles
limit
Optional[int]
Applied limit parameter
offset
Optional[int]
Applied offset parameter
total
Optional[int]
Total number of articles available
Raises
ValidationError: Invalid parameters or malformed requestAPIError: Server-side errors or invalid responsesAuthenticationError: Invalid API keyRateLimitError: Too many requestsChainGPTError: Other SDK-related errors
Data Models Reference
NewsArticleModel
Represents a single news article with complete metadata.
CategoryModel
SubCategoryModel
TokenModel
MediaModel
GetNewsResponseModel
Usage Examples
Basic News Retrieval
Filtering by Category and Sub-Category
Search with Keywords
Date Range Filtering
Pagination Implementation
Complex Multi-Filter Query
Error Handling
Exception Types
The SDK provides specific exception types for different error scenarios:
Comprehensive Error Handling
Error Handling with Retry Logic
Common Category and Token IDs
Categories
8
NFT
Non-Fungible Token related news
12
DeFi
Decentralized Finance news
Sub-Categories (Ethereum-related)
15
Ethereum
Ethereum blockchain news
39
Ethereum
Alternative Ethereum category
Tokens
79
Bitcoin
BTC
Bitcoin cryptocurrency
1027
Ethereum
ETH
Ethereum cryptocurrency
Note: These IDs are examples and may change. Use the API responses to discover current category, sub-category, and token IDs. Consider caching this information for better performance.
Discovering Available IDs
Best Practices
1. Efficient API Usage
2. Proper Pagination
3. Error Handling and Logging
4. Resource Management
5. Caching for Performance
6. Rate Limiting
Last updated
Was this helpful?