Closed kipply closed 1 year ago
Related / to expand on this issue: the current default export is a singleton instance of the Cohere
class: https://github.com/cohere-ai/cohere-node/blob/b27234a427c1082b706520af69bfe897bdb072b7/cohere.ts#L117
This means that it's not possible for a user to create multiple distinct instances with their own API keys. i.e. something like this is not possible:
import { Client } from 'cohere-ai';
const client1 = new Client();
client1.init('key1');
const client2 = new Client();
client2.init('key2');
Instead, we only have the singleton instance:
import cohere from 'cohere-ai';
cohere.init('key1');
An example use case when the former is useful is implementing a wrapping service for the Cohere API, e.g. a GraphQL server: https://github.com/elliottsj/cohere-graphql/blob/d3b616ac3b3b3a420a3a14a39c019ff444251774/src/routes/api/graphql.ts#L190
When using the singleton instance, there's a greater risk that users' API keys are shared between requests.
It's better for