@friendliai/ai-provider
Version:
<!-- header start --> <p align="center"> <img src="https://huggingface.co/datasets/FriendliAI/documentation-images/resolve/main/model-card-assets/friendliai.png" width="100%" alt="FriendliAI Logo"> </p> <!-- header end -->
175 lines (168 loc) • 5.66 kB
TypeScript
import { z } from 'zod';
import { ProviderV3, LanguageModelV3, EmbeddingModelV3, ImageModelV3, TranscriptionModelV3, SpeechModelV3 } from '@ai-sdk/provider';
import { Tool, FetchFunction } from '@ai-sdk/provider-utils';
declare const friendliaiErrorSchema: z.ZodUnion<readonly [z.ZodObject<{
error: z.ZodObject<{
message: z.ZodString;
}, z.core.$loose>;
}, z.core.$loose>, z.ZodObject<{
message: z.ZodString;
error: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, z.core.$strip>]>;
type FriendliAIErrorData = z.infer<typeof friendliaiErrorSchema>;
declare const FriendliAIServerlessModelIds: readonly ["google/gemma-4-31B-it", "zai-org/GLM-5.1", "zai-org/GLM-5", "meta-llama/Llama-3.3-70B-Instruct", "meta-llama-3.3-70b-instruct", "meta-llama/Llama-3.1-8B-Instruct", "meta-llama-3.1-8b-instruct", "Qwen/Qwen3-235B-A22B-Instruct-2507", "deepseek-ai/DeepSeek-V3.2", "openai/whisper-large-v3", "MiniMaxAI/MiniMax-M2.5", "LGAI-EXAONE/K-EXAONE-236B-A23B"];
type FriendliAIServerlessModelId = (typeof FriendliAIServerlessModelIds)[number];
type FriendliAILanguageModelId = FriendliAIServerlessModelId | (string & {});
/**
* Web search tool - searches the web for information.
* @beta
*/
declare function webSearch(): Tool;
/**
* Web URL tool - fetches content from a specific URL.
* @beta
*/
declare function webUrl(): Tool;
/**
* Math calendar tool - performs calendar-related calculations.
* @beta
*/
declare function mathCalendar(): Tool;
/**
* Math statistics tool - performs statistical calculations.
* @beta
*/
declare function mathStatistics(): Tool;
/**
* Math calculator tool - performs arithmetic calculations.
* @beta
*/
declare function mathCalculator(): Tool;
/**
* Python interpreter tool - executes Python code.
* @beta
*/
declare function codePythonInterpreter(): Tool;
/**
* Linkup search tool - searches the web for real-time information with citations.
* @see https://www.linkup.so
*/
declare function linkupSearch(): Tool;
declare const friendliTools: {
webSearch: typeof webSearch;
webUrl: typeof webUrl;
mathCalendar: typeof mathCalendar;
mathStatistics: typeof mathStatistics;
mathCalculator: typeof mathCalculator;
codePythonInterpreter: typeof codePythonInterpreter;
linkupSearch: typeof linkupSearch;
};
type Pricing = {
inputToken?: number;
cachedInputToken?: number;
outputToken?: number;
responseTime?: number;
audioMinute?: number;
unitType?: 'TOKEN' | 'SECOND' | 'AUDIO_MINUTE';
currency?: string;
unit?: string;
};
type FriendliAvailableModel = {
id: string;
name?: string | null;
description?: string | null;
pricing?: Pricing;
warm?: boolean;
cold?: boolean;
contextLength?: number | null;
};
type FriendliAvailableModelsResponse = {
models: FriendliAvailableModel[];
};
interface FriendliAIProviderSettings {
/**
* FriendliAI API key. (FRIENDLI_TOKEN)
*/
apiKey?: string;
/**
* Base URL for the API calls.
*/
baseURL?: string | 'auto' | 'dedicated' | 'serverless' | 'serverless-tools';
/**
* Custom headers to include in the requests.
*/
headers?: Record<string, string>;
/**
* FriendliAI Team ID.
*/
teamId?: string;
/**
* Custom fetch implementation. You can use it as a middleware to intercept requests,
* or to provide a custom fetch implementation for e.g. testing.
*/
fetch?: FetchFunction;
/**
* Whether to include usage information in the response.
*/
includeUsage?: boolean;
}
interface FriendliAIProvider extends ProviderV3 {
/**
* Creates a model for text generation.
*/
(modelId: FriendliAILanguageModelId): LanguageModelV3;
/**
* Creates a chat model for text generation.
*/
languageModel(modelId: FriendliAILanguageModelId): LanguageModelV3;
/**
* Creates a chat model for text generation.
*/
chat(modelId: FriendliAILanguageModelId): LanguageModelV3;
/**
* Creates a completion model for text generation.
*/
completion(modelId: FriendliAILanguageModelId): LanguageModelV3;
/**
* Creates an embedding model for text generation.
* TODO: Implement for Dedicated users
*/
embedding(modelId: string & {}): LanguageModelV3;
embeddingModel(modelId: string & {}): LanguageModelV3;
/**
* Returns the available models and their metadata.
*/
getAvailableModels(options?: {
graphqlURL?: string;
}): Promise<FriendliAvailableModelsResponse>;
embedding(modelId: string & {}): EmbeddingModelV3;
embeddingModel(modelId: string & {}): EmbeddingModelV3;
/**
* Creates a model for image generation.
* TODO: Implement for Dedicated users
*/
imageModel(modelId: string & {}): ImageModelV3;
/**
* Creates a model for transcription.
* TODO: Implement for Dedicated users
*/
transcription(modelId: string & {}): TranscriptionModelV3;
/**
* Creates a model for speech generation.
* TODO: Implement for Dedicated users
*/
speech(modelId: string & {}): SpeechModelV3;
/**
* Friendli-specific tools.
*/
tools: typeof friendliTools;
}
/**
Create an FriendliAI provider instance.
*/
declare function createFriendli(options?: FriendliAIProviderSettings): FriendliAIProvider;
/**
* Default FriendliAI provider instance.
*/
declare const friendli: FriendliAIProvider;
export { type FriendliAIErrorData, type FriendliAIProvider, type FriendliAIProviderSettings, type FriendliAvailableModel, type FriendliAvailableModelsResponse, createFriendli, friendli };