Supported features
Prerequisites
- Node.js 18+
- A CometAPI account with an active API key — get yours here
1
Install the provider
Install
@cometapi/ai-sdk-provider alongside the AI SDK core package:2
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.
3
Import the provider
Import the default provider instance:To override the API key, base URL, or other settings, use
createCometAPI: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:
Model methods
The provider exposes several model constructors:
Browse the full list of available model IDs on the Models page.
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.