Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chaingpt/ainews

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chaingpt/ainews

SDK for AINews

  • 0.0.2
  • npm
  • Socket score

Version published
Weekly downloads
20
increased by233.33%
Maintainers
3
Weekly downloads
 
Created
Source

ChainGPT AI News SDK

This library provides convenient access to the ChainGPT AI News REST API from TypeScript or JavaScript.

Installation

npm install --save @chaingpt/ainews
# or
yarn add ainews

Usage

import { AINews } from '@chaingpt/ainews';

const ainews = new AINews({
  apiKey: 'Your ChainGPT API Key',
});

async function main() {
  const news = await ainews.getNews({});
}

main();

Handling errors

When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of AINewsError will be thrown:

import { Errors } from '@chaingpt/ainews';
async function main() {
  ainews.getNews({}).then((res)=>{}).catch((err)=>{
      if (err instanceof Errors.AINewsError) {
        if (err instanceof Errors.InvalidApiKeyError) {
            console.log("Invalid Api Key Error")
        } else if (err instanceof Errors.RateLimitExceededError) {
            console.log("Rate limit exceeded Error")
        }
      }
  });
}

main();

Error codes are as followed:

Status CodeError Type
403InvalidApiKeyError
429RateLimitExceededError
N/AAINewsError

Keywords

FAQs

Package last updated on 15 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc