Supported features
| Feature | Method | Status |
|---|---|---|
| Text generation | generateText() | Supported |
| Text streaming | streamText() | Supported |
| Text embeddings | textEmbeddingModel() | Supported |
| Image generation | imageModel() | Supported |
Prerequisites
- Node.js 18+
- A CometAPI account with an active API key — get yours here
Set your API key
The provider reads the
COMETAPI_KEY environment variable by default:Use environment variables to avoid hardcoding credentials in your source code.
Usage
Generate text
UsegenerateText() for a single-shot response:
Stream text
UsestreamText() for real-time chunked output:
Generate embeddings
UsetextEmbeddingModel() to create vector embeddings:
Generate images
UseimageModel() to generate images from text prompts:
Provider configuration
createCometAPI accepts the following options:
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | process.env.COMETAPI_KEY | CometAPI API key |
baseURL | string | https://api.cometapi.com/v1 | API base URL |
headers | Record<string, string> | — | Custom request headers |
fetch | FetchFunction | — | Custom fetch implementation |
Model methods
The provider exposes several model constructors:| Method | Returns | Use case |
|---|---|---|
cometapi(modelId) | LanguageModelV2 | Text generation and streaming (shorthand) |
cometapi.chatModel(modelId) | LanguageModelV2 | Chat completions |
cometapi.completionModel(modelId) | LanguageModelV2 | Text completions |
cometapi.languageModel(modelId) | LanguageModelV2 | Alias for chatModel |
cometapi.textEmbeddingModel(modelId) | EmbeddingModelV2 | Text embeddings |
cometapi.imageModel(modelId) | ImageModelV2 | Image generation |
Tips and troubleshooting
Tips and troubleshooting
- Model selection: Any model from the CometAPI model catalog works with the corresponding model method — chat models via
cometapi(), embedding models viatextEmbeddingModel(), image models viaimageModel(). - Fine-tuning responses: Pass
temperature,maxTokens, andtopPdirectly togenerateText()orstreamText(), e.g.generateText(\{..., temperature: 0.7\}). - Error handling: Wrap calls in
try/catchto handle authentication errors, rate limits, or network issues. - Security: Never commit API keys to version control. Use environment variables or a secrets manager.
- Rate limits: Monitor usage in the CometAPI console.