npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

Iโ€™ve always been into building performant and accessible sites, but lately Iโ€™ve been taking it extremely seriously. So much so that Iโ€™ve been building a tool to help me optimize and monitor the sites that I build to make sure that Iโ€™m making an attempt to offer the best experience to those who visit them. If youโ€™re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, ๐Ÿ‘‹, Iโ€™m Ryan Hefnerย  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If youโ€™re interested in other things Iโ€™m working on, follow me on Twitter or check out the open source projects Iโ€™ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soonโ€“ish.

Open Software & Tools

This site wouldnโ€™t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you ๐Ÿ™

ยฉ 2025 โ€“ย Pkg Stats / Ryan Hefner

@embedapi/core

v1.0.9

Published

๐Ÿ”ฅ ONE API KEY TO RULE THEM ALL! Access ANY AI model instantly through our game-changing unified API. Build AI apps in minutes, not months! The ultimate all-in-one AI agent solution you've been waiting for! ๐Ÿš€

Downloads

163

Readme

EmbedAPIClient

๐Ÿ”ฅ ONE API KEY TO RULE THEM ALL! Access ANY AI model instantly through our game-changing unified API. Build AI apps in minutes, not months! The ultimate all-in-one AI agent solution you've been waiting for! ๐Ÿš€

Visit embedapi.com to get your API key and start building!

Installation

Using npm:

npm install @embedapi/core

Using yarn:

yarn add @embedapi/core

Using pnpm:

pnpm add @embedapi/core

Initialization

const EmbedAPIClient = require('@embedapi/core');

# Regular API client
const client = new EmbedAPIClient('your-api-key');

# Agent mode client
const agentClient = new EmbedAPIClient('your-agent-id', { isAgent: true });

# Debug mode client
const debugClient = new EmbedAPIClient('your-api-key', { debug: true });

# Agent and debug mode client
const debugAgentClient = new EmbedAPIClient('your-agent-id', { 
    isAgent: true, 
    debug: true 
});

Constructor Parameters

  • apiKey (string): Your API key for regular mode, or agent ID for agent mode
  • options (object, optional): Configuration options
    • isAgent (boolean, optional): Set to true to use agent mode. Defaults to false
    • debug (boolean, optional): Set to true to enable debug logging. Defaults to false

Methods

1. generate({ service, model, messages, ...options })

Generates text using the specified AI service and model.

Parameters

  • service (string): The name of the AI service (e.g., 'openai')
  • model (string): The model to use (e.g., 'gpt-4o')
  • messages (array): An array of message objects containing conversation history
  • maxTokens (number, optional): Maximum number of tokens to generate
  • temperature (number, optional): Sampling temperature
  • topP (number, optional): Top-p sampling parameter
  • frequencyPenalty (number, optional): Frequency penalty parameter
  • presencePenalty (number, optional): Presence penalty parameter
  • stopSequences (array, optional): Stop sequences for controlling response generation
  • tools (array, optional): Array of function definitions for tool use
  • toolChoice (string|object, optional): Tool selection preferences
  • enabledTools (array, optional): List of enabled tool names
  • userId (string, optional): Optional user identifier for agent mode

Usage Example

// Regular mode
const response = await client.generate({
    service: 'openai',
    model: 'gpt-4o',
    messages: [{ role: 'user', content: 'Hello' }]
});

// Agent mode
const agentResponse = await agentClient.generate({
    service: 'openai',
    model: 'gpt-4o',
    messages: [{ role: 'user', content: 'Hello' }]
});

2. stream({ service, model, messages, ...options })

Streams text generation using the specified AI service and model.

Parameters

Same as generate(), plus:

  • streamOptions (object, optional): Stream-specific configuration options

Response Format

The stream emits Server-Sent Events (SSE) with two types of messages:

  1. Content Chunks:
{
    "content": "Generated text chunk",
    "role": "assistant"
}
  1. Final Statistics:
{
    "type": "done",
    "tokenUsage": 17,
    "cost": 0.000612
}

Usage Example

// Regular mode
const streamResponse = await client.stream({
    service: 'openai',
    model: 'gpt-4o',
    messages: [{ role: 'user', content: 'Hello' }]
});

// Agent mode
const agentStreamResponse = await agentClient.stream({
    service: 'openai',
    model: 'gpt-4o',
    messages: [{ role: 'user', content: 'Hello' }]
});

// Process the stream
const reader = streamResponse.body.getReader();
const decoder = new TextDecoder();

while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    
    const chunk = decoder.decode(value);
    const lines = chunk.split('\n');
    
    for (const line of lines) {
        if (line.startsWith('data: ')) {
            const data = JSON.parse(line.slice(6));
            if (data.type === 'done') {
                console.log('Stream stats:', {
                    tokenUsage: data.tokenUsage,
                    cost: data.cost
                });
            } else {
                console.log('Content:', data.content);
            }
        }
    }
}

3. listModels()

Lists all available models.

const models = await client.listModels();

4. testAPIConnection()

Tests the connection to the API.

const isConnected = await client.testAPIConnection();

Error Handling

All methods throw errors if the API request fails:

try {
    const response = await client.generate({
        service: 'openai',
        model: 'gpt-4o',
        messages: [{ role: 'user', content: 'Hello' }]
    });
} catch (error) {
    console.error('Error:', error.message);
}

Authentication

The client supports two authentication modes:

  1. Regular Mode (default)

    • Uses API key in request headers
    • Initialize with: new EmbedAPIClient('your-api-key')
  2. Agent Mode

    • Uses agent ID in request body
    • Initialize with: new EmbedAPIClient('your-agent-id', { isAgent: true })
    • Optional userId parameter available for request tracking

License

MIT