Skip to main content
The CometAPI provider for the AI SDK gives you access to 500+ AI models through a unified TypeScript interface. Use it to add text generation, streaming, embeddings, and image generation to any Node.js or Edge runtime application.

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

Use generateText() for a single-shot response:

Stream text

Use streamText() for real-time chunked output:

Generate embeddings

Use textEmbeddingModel() to create vector embeddings:

Generate images

Use imageModel() 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.
  • Model selection: Any model from the CometAPI model catalog works with the corresponding model method — chat models via cometapi(), embedding models via textEmbeddingModel(), image models via imageModel().
  • Fine-tuning responses: Pass temperature, maxTokens, and topP directly to generateText() or streamText(), e.g. generateText(\{..., temperature: 0.7\}).
  • Error handling: Wrap calls in try/catch to 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.
Last modified on July 2, 2026