@302ai/ai-sdk
Version:
The **[302AI provider](https://sdk.vercel.ai/providers/ai-sdk-providers/)** for the [AI SDK](https://sdk.vercel.ai/docs) contains image model support for the [302AI](https://302.ai) platform.
314 lines (298 loc) • 18.9 kB
TypeScript
import { ProviderV3, LanguageModelV3, EmbeddingModelV3, ImageModelV3, SpeechModelV3, RerankingModelV3, TranscriptionModelV3, TranscriptionModelV3CallOptions } from '@ai-sdk/provider';
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
import { InferSchema, FetchFunction, Resolvable } from '@ai-sdk/provider-utils';
import { z } from 'zod';
type AI302ImageModelId = 'flux-v1.1-ultra' | 'flux-pro-v1.1' | 'flux-pro' | 'flux-dev' | 'flux-schnell' | 'flux-1-krea' | 'flux-kontext-max' | 'flux-kontext-pro' | 'flux-2-pro' | 'flux-2-flex' | 'flux-2-max' | 'ideogram/V_1' | 'ideogram/V_1_TURBO' | 'ideogram/V_2' | 'ideogram/V_2_TURBO' | 'ideogram/V_2A' | 'ideogram/V_2A_TURBO' | 'dall-e-3' | 'recraftv3' | 'recraftv2' | 'sdxl-lightning' | 'sdxl-lightning-v2' | 'sdxl-lightning-v3' | 'kolors' | 'aura-flow' | 'photon-1' | 'photon-flash-1' | 'sdxl' | 'sd3-ultra' | 'sd3v2' | 'sd3.5-large' | 'sd3.5-large-turbo' | 'sd3.5-medium' | 'midjourney/6.0' | 'midjourney/6.1' | 'midjourney/7.0' | 'nijijourney/6.0' | 'google-imagen-3' | 'google-imagen-3-fast' | 'google-imagen-4-preview' | 'doubao-general-v2.1-l' | 'doubao-general-v2.0-l' | 'doubao-general-v2.0' | 'doubao-general-v3.0' | 'doubao-seedream-3-0-t2i-250415' | 'doubao-seedream-4-0-250828' | 'doubao-seedream-4-5-251128' | 'lumina-image-v2' | 'omnigen-v1' | 'playground-v25' | 'cogview-4' | 'cogview-4-250304' | 'minimaxi-image-01' | 'irag-1.0' | 'hidream-i1-full' | 'hidream-i1-dev' | 'hidream-i1-fast' | 'gpt-image-1' | 'gpt-image-1.5' | 'bagel' | 'soul' | 'kling-v1' | 'kling-v1-5' | 'kling-v2' | 'kling-v2-1' | 'qwen-image' | 'gemini-2.5-flash-image-preview' | 'gemini-3-pro-image-preview' | 'z-image-turbo' | 'vidu-viduq1' | 'vidu-viduq2' | 'kling-o1' | 'wan2.6-image' | (string & {});
interface AI302ImageSettings {
}
type AI302ChatModelId = 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-16k' | 'gpt-4' | 'gpt-4-0125-preview' | 'gpt-4-0613' | 'gpt-4-1106-preview' | 'gpt-4-32k' | 'gpt-4-32k-0613' | 'gpt-4-turbo-preview' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-instruct' | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307' | 'qwen-turbo' | 'qwen-plus' | 'qwen-max' | 'qwen-max-latest' | 'glm-4-0520' | 'glm-4v' | 'Baichuan2-53B' | 'Baichuan2-Turbo' | 'Baichuan2-Turbo-192k' | 'moonshot-v1-128k' | 'moonshot-v1-32k' | 'moonshot-v1-8k' | 'ernie-4.0-8k' | 'gpt-4-turbo' | 'gemini-1.5-pro' | 'command-r-plus' | 'deepseek-chat' | 'deepseek-reasoner' | 'gpt-4o' | 'qwen-long' | 'glm-4-air' | 'glm-4-flash' | 'qwen2-72b-instruct' | 'qwen2-7b-instruct' | 'Doubao-pro-32k' | 'Doubao-pro-128k' | 'qwen-vl-max' | 'qwen-vl-plus' | 'claude-3-5-sonnet-20240620' | 'step-1v-32k' | 'step-1v-8k' | 'yi-large' | 'yi-large-rag' | 'yi-vision' | 'yi-medium-200k' | 'generalv3.5' | '4.0Ultra' | 'general' | 'ernie-4.0-turbo-8k' | 'Baichuan3-Turbo' | 'Baichuan3-Turbo-128k' | 'Baichuan4' | 'XuanYuan-70B-Chat-4bit' | 'gemma2-9b-it' | 'SenseChat-5' | 'SenseChat-Turbo' | 'gemini-1.5-pro-001' | 'gemini-1.5-flash-001' | 'codegeex-4' | 'google/gemma-2-27b-it' | 'gpt-4o-mini-2024-07-18' | 'llama3.1-405b' | 'llama3.1-70b' | 'llama3.1-8b' | 'mistral-large-2' | 'deepseek-ai/DeepSeek-V2.5' | 'step-2-16k' | 'command-r' | 'gpt-4-plus' | 'gemini-1.5-pro-exp-0827' | 'abab6.5s-chat' | 'gpt-4o-2024-08-06' | 'chatgpt-4o-latest' | 'glm-4-long' | 'gemini-1.5-pro-latest' | 'hunyuan-lite' | 'hunyuan-standard' | 'hunyuan-standard-256K' | 'hunyuan-pro' | 'hunyuan-code' | 'hunyuan-role' | 'hunyuan-functioncall' | 'hunyuan-vision' | 'Qwen/Qwen2-7B-Instruct' | 'glm-4-plus' | 'glm-4v-plus' | 'pplx-70b-online' | 'pplx-8b-online' | 'pplx-405b-online' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o1-mini' | 'o1-mini-2024-09-12' | 'qwen-math-plus' | 'qwen2.5-72b-instruct' | 'qwen2.5-32b-instruct' | 'qwen2.5-14b-instruct' | 'qwen2.5-3b-instruct' | 'qwen2.5-math-72b-instruct' | 'qwen2.5-coder-7b-instruct' | 'gemini-1.5-pro-002' | 'gemini-1.5-flash-002' | 'llama3.2-90b' | 'llama3.2-11b' | 'gpt-4o-2024-05-13' | 'yi-lightning' | 'claude-3-5-sonnet-20241022' | 'claude-3-5-sonnet-latest' | 'step-1.5v-turbo' | 'claude-3-5-haiku-20241022' | 'grok-beta' | 'gpt-4-turbo-2024-04-09' | 'gemini-exp-1114' | 'qwen-turbo-latest' | 'qwen-turbo-2024-11-01' | 'pixtral-large-2411' | 'mistral-large-2411' | 'gpt-4o-2024-11-20' | 'gpt-4o-plus' | 'ernie-4.0-turbo-128k' | 'gemini-exp-1121' | 'grok-vision-beta' | 'Qwen/QwQ-32B-Preview' | 'Doubao-vision-pro-32k' | 'AIDC-AI/Marco-o1' | 'abab7-chat-preview' | 'coder-claude-3-5-sonnet-20240620' | 'coder-claude-3-5-sonnet-20241022' | 'nova-pro' | 'nova-lite' | 'nova-micro' | 'gemini-exp-1206' | 'qwq-32b-preview' | 'llama3.3-70b' | 'qwen-vl-ocr' | 'meta-llama/Llama-3.3-70B-Instruct' | 'o1-plus' | 'gemma-2-27b' | 'gemini-2.0-flash-exp' | 'gemini-1.5-flash-8b' | 'Doubao-Vision-Lite-32k' | 'qwen2.5-coder-32b-instruct' | 'o1' | 'grok-2-1212' | 'grok-2-vision-1212' | 'deepseek-ai/deepseek-vl2' | 'deepseek-vl2' | 'marco-o1' | 'gemini-2.0-flash-thinking-exp-1219' | 'qwen2.5-7b-instruct' | 'o1-2024-12-17' | 'Qwen/QVQ-72B-Preview' | 'QVQ-72B-Preview' | 'Pro/google/gemma-2-9b-it' | 'Qwen/Qwen2.5-Coder-32B-Instruct' | 'Qwen/Qwen2-VL-72B-Instruct' | 'OpenGVLab/InternVL2-26B' | 'TeleAI/TeleMM' | 'Qwen/Qwen2.5-72B-Instruct-128K' | 'Qwen/Qwen2.5-32B-Instruct' | 'Qwen/Qwen2.5-14B-Instruct' | 'Qwen/Qwen2.5-7B-Instruct' | 'Qwen/Qwen2.5-Coder-7B-Instruct' | 'TeleAI/TeleChat2' | 'internlm/internlm2_5-20b-chat' | 'internlm/internlm2_5-7b-chat' | 'meta-llama/Meta-Llama-3.1-405B-Instruct' | 'meta-llama/Meta-Llama-3.1-8B-Instruct' | 'meta-llama/Meta-Llama-3.1-70B-Instruct' | 'Qwen/Qwen2-1.5B-Instruct' | 'THUDM/glm-4-9b-chat' | 'THUDM/chatglm3-6b' | '01-ai/Yi-1.5-9B-Chat-16K' | '01-ai/Yi-1.5-6B-Chat' | '01-ai/Yi-1.5-34B-Chat-16K' | 'google/gemma-2-9b-it' | 'Vendor-A/Qwen/Qwen2.5-72B-Instruct' | 'Pro/Qwen/Qwen2.5-Coder-7B-Instruct' | 'Pro/Qwen/Qwen2-VL-7B-Instruct' | 'Pro/OpenGVLab/InternVL2-8B' | 'Pro/Qwen/Qwen2.5-7B-Instruct' | 'Pro/meta-llama/Meta-Llama-3.1-8B-Instruct' | 'Pro/Qwen/Qwen2-7B-Instruct' | 'Pro/Qwen/Qwen2-1.5B-Instruct' | 'Pro/THUDM/glm-4-9b-chat' | 'MiniMax-Text-01' | 'moonshot-v1-8k-vision-preview' | 'moonshot-v1-32k-vision-preview' | 'moonshot-v1-128k-vision-preview' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku' | (string & {});
interface AI302ChatSettings {
/**
* Enable thinking mode for models that support it (e.g., DeepSeek).
* When enabled, the model outputs reasoning content before the final answer.
*
* During tool calling in thinking mode, reasoning_content must be passed back
* to the API to continue the model's chain of thought.
*
* @example
* ```typescript
* ai302('deepseek-chat', { thinking: { type: 'enabled' } })
* ```
*/
thinking?: {
type: 'enabled' | 'disabled';
};
}
/**
* 302AI Embedding Model IDs
*
* Supported providers:
* - OpenAI: text-embedding-3-small, text-embedding-3-large, text-embedding-ada-002
* - Jina: jina-clip-v1/v2, jina-embeddings-v2-base-*, jina-embeddings-v3
* - Voyage: voyage-3-large, voyage-3.5, voyage-code-3, etc.
* - Google: gemini-embedding-001
* - Qwen: Qwen/Qwen3-Embedding-*
* - 智谱: embedding-2, embedding-3, zhipu-embedding-2
* - BAAI: BAAI/bge-large-*, BAAI/bge-m3
* - Others: Baichuan-Text-Embedding, bce-embedding-base_v1
*/
type AI302EmbeddingModelId = 'text-embedding-3-small' | 'text-embedding-3-large' | 'text-embedding-ada-002' | 'jina-clip-v1' | 'jina-clip-v2' | 'jina-embeddings-v2-base-en' | 'jina-embeddings-v2-base-es' | 'jina-embeddings-v2-base-de' | 'jina-embeddings-v2-base-zh' | 'jina-embeddings-v2-base-code' | 'jina-embeddings-v3' | 'voyage-3-large' | 'voyage-context-3' | 'voyage-3.5' | 'voyage-3.5-lite' | 'voyage-code-3' | 'voyage-finance-2' | 'voyage-law-2' | 'voyage-code-2' | 'gemini-embedding-001' | 'Qwen/Qwen3-Embedding-8B' | 'Qwen/Qwen3-Embedding-4B' | 'Qwen/Qwen3-Embedding-0.6B' | 'embedding-3' | 'embedding-2' | 'zhipu-embedding-2' | 'BAAI/bge-large-en-v1.5' | 'BAAI/bge-large-zh-v1.5' | 'BAAI/bge-m3' | 'Baichuan-Text-Embedding' | 'bce-embedding-base_v1' | (string & {});
/**
* Provider options for 302AI embedding models
*/
declare const ai302EmbeddingProviderOptions: z.ZodObject<{
dimensions: z.ZodOptional<z.ZodNumber>;
user: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
type AI302EmbeddingProviderOptions = z.infer<typeof ai302EmbeddingProviderOptions>;
/**
* 302AI Reranking Model IDs
*
* Supported providers:
* - Jina: jina-reranker-v2-base-multilingual, jina-reranker-v1-*, jina-colbert-v1-en
* - BCE (有道): bce-reranker-base_v1
* - BAAI (智源): bge-reranker-v2-m3
* - Qwen (硅基流动): Qwen/Qwen3-Reranker-*
* - Voyage: rerank-2.5, rerank-2.5-lite
*/
type AI302RerankingModelId = 'jina-reranker-v2-base-multilingual' | 'jina-reranker-v1-base-en' | 'jina-reranker-v1-tiny-en' | 'jina-reranker-v1-turbo-en' | 'jina-colbert-v1-en' | 'bce-reranker-base_v1' | 'bge-reranker-v2-m3' | 'Qwen/Qwen3-Reranker-8B' | 'Qwen/Qwen3-Reranker-4B' | 'Qwen/Qwen3-Reranker-0.6B' | 'rerank-2.5' | 'rerank-2.5-lite' | (string & {});
/**
* Provider options for 302AI reranking models
*/
declare const ai302RerankingProviderOptions: z.ZodObject<{
returnDocuments: z.ZodOptional<z.ZodBoolean>;
}, z.core.$strip>;
type AI302RerankingProviderOptions = z.infer<typeof ai302RerankingProviderOptions>;
/**
* 302AI TTS Provider types
*/
type AI302TTSProvider = 'openai' | 'doubao' | 'azure' | 'fish' | 'minimaxi' | 'dubbingx' | 'elevenlabs' | 'elevenlabs-official' | 'meruka' | 'google' | 'qwen';
/**
* 302AI Speech Model ID
* Format: "provider/voice" e.g. "openai/alloy", "azure/zh-CN-XiaoxiaoNeural"
*/
type AI302SpeechModelId = `${AI302TTSProvider}/${string}` | (string & {});
/**
* Provider-specific options for 302AI TTS
*/
declare const ai302SpeechProviderOptionsSchema: z.ZodObject<{
runAsync: z.ZodOptional<z.ZodBoolean>;
webhook: z.ZodOptional<z.ZodString>;
timeout: z.ZodOptional<z.ZodNumber>;
model: z.ZodOptional<z.ZodString>;
volume: z.ZodOptional<z.ZodNumber>;
emotion: z.ZodOptional<z.ZodString>;
pollInterval: z.ZodOptional<z.ZodNumber>;
maxPollAttempts: z.ZodOptional<z.ZodNumber>;
}, z.core.$strip>;
type AI302SpeechProviderOptions = z.infer<typeof ai302SpeechProviderOptionsSchema>;
/**
* 302AI Transcription Provider types
*/
type AI302TranscriptionProvider = 'openai' | 'doubao' | 'elevenlabs' | 'siliconflow';
/**
* 302AI Transcription Model ID
*/
type AI302TranscriptionModelId = 'whisper-1' | 'gpt-4o-transcribe' | 'gpt-4o-mini-transcribe' | 'gpt-4o-transcribe-diarize' | 'recognize' | 'scribe_v1' | 'scribe_v1_experimental' | 'sensevoice' | (string & {});
/**
* Response format for transcription API
*/
type AI302TranscriptionResponseFormat = 'json' | 'text' | 'srt' | 'vtt' | 'verbose_json' | 'diarized_json';
/**
* Provider-specific options for 302AI Transcription
*/
declare const ai302TranscriptionProviderOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
language?: string | undefined;
prompt?: string | undefined;
temperature?: number | undefined;
responseFormat?: "text" | "json" | "srt" | "vtt" | "verbose_json" | "diarized_json" | undefined;
timestampGranularities?: ("word" | "segment")[] | undefined;
include?: string[] | undefined;
}>;
type AI302TranscriptionProviderOptions = InferSchema<typeof ai302TranscriptionProviderOptionsSchema>;
interface AI302ProviderSettings {
/**
AI302 API key. Default value is taken from the `AI302_API_KEY`
environment variable.
*/
apiKey?: string;
/**
Base URL for the API calls.
*/
baseURL?: string;
/**
Custom headers to include in the requests.
*/
headers?: Record<string, 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;
}
interface AI302Provider extends ProviderV3 {
/**
Creates a model for text generation.
*/
(modelId: AI302ChatModelId, settings?: AI302ChatSettings): LanguageModelV3;
/**
Creates a chat model for text generation.
*/
languageModel(modelId: AI302ChatModelId, settings?: AI302ChatSettings): LanguageModelV3;
/**
Creates a chat model for text generation.
*/
chatModel(modelId: AI302ChatModelId, settings?: AI302ChatSettings): LanguageModelV3;
/**
Creates a text embedding model.
Use providerOptions in embed() call for model-specific options like dimensions.
*/
textEmbeddingModel(modelId: AI302EmbeddingModelId): EmbeddingModelV3;
/**
Creates a text embedding model (alias for textEmbeddingModel).
*/
embeddingModel(modelId: AI302EmbeddingModelId): EmbeddingModelV3;
/**
Creates a model for image generation.
*/
image(modelId: AI302ImageModelId, settings?: AI302ImageSettings): ImageModelV3;
/**
Creates a model for image generation (alias for image).
*/
imageModel(modelId: AI302ImageModelId, settings?: AI302ImageSettings): ImageModelV3;
/**
Creates a model for speech generation (TTS).
@param modelId Format: "provider/voice" e.g. "openai/alloy", "azure/zh-CN-XiaoxiaoNeural"
*/
speech(modelId: AI302SpeechModelId): SpeechModelV3;
/**
Creates a model for speech generation (alias for speech).
*/
speechModel(modelId: AI302SpeechModelId): SpeechModelV3;
/**
Creates a model for reranking documents.
*/
reranking(modelId: AI302RerankingModelId): RerankingModelV3;
/**
Creates a model for reranking documents (alias for reranking).
*/
rerankingModel(modelId: AI302RerankingModelId): RerankingModelV3;
/**
Creates a model for audio transcription (speech-to-text).
@param modelId The transcription model ID, e.g. "whisper-1", "gpt-4o-transcribe"
*/
transcription(modelId: AI302TranscriptionModelId): TranscriptionModelV3;
/**
Creates a model for audio transcription (alias for transcription).
*/
transcriptionModel(modelId: AI302TranscriptionModelId): TranscriptionModelV3;
}
declare function createAI302(options?: AI302ProviderSettings): AI302Provider;
declare const ai302: AI302Provider;
type AI302Config = {
provider: string;
url: (options: {
modelId: string;
path: string;
}) => string;
headers: () => Resolvable<Record<string, string | undefined>>;
midjourneyHeaders?: () => Resolvable<Record<string, string | undefined>>;
fetch?: FetchFunction;
};
declare class AI302LanguageModel implements LanguageModelV3 {
readonly modelId: AI302ChatModelId;
private readonly settings;
private readonly config;
readonly specificationVersion = "v3";
readonly defaultObjectGenerationMode = "json";
readonly supportedUrls: {
'*/*': RegExp[];
};
constructor(modelId: AI302ChatModelId, settings: AI302ChatSettings, config: AI302Config);
get provider(): string;
private getArgs;
doGenerate(options: Parameters<LanguageModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
doStream(options: Parameters<LanguageModelV3['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
}
declare class AI302EmbeddingModel implements EmbeddingModelV3 {
readonly specificationVersion = "v3";
readonly modelId: AI302EmbeddingModelId;
readonly maxEmbeddingsPerCall = 2048;
readonly supportsParallelCalls = true;
private readonly config;
get provider(): string;
constructor(modelId: AI302EmbeddingModelId, config: AI302Config);
doEmbed({ values, headers, abortSignal, providerOptions, }: Parameters<EmbeddingModelV3['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV3['doEmbed']>>>;
}
declare class AI302RerankingModel implements RerankingModelV3 {
readonly specificationVersion = "v3";
readonly modelId: AI302RerankingModelId;
private readonly config;
get provider(): string;
constructor(modelId: AI302RerankingModelId, config: AI302Config);
doRerank({ documents, query, topN, headers, abortSignal, providerOptions, }: Parameters<RerankingModelV3['doRerank']>[0]): Promise<Awaited<ReturnType<RerankingModelV3['doRerank']>>>;
}
interface AI302SpeechModelConfig extends AI302Config {
_internal?: {
currentDate?: () => Date;
};
}
declare class AI302SpeechModel implements SpeechModelV3 {
readonly modelId: AI302SpeechModelId;
private readonly config;
readonly specificationVersion = "v3";
constructor(modelId: AI302SpeechModelId, config: AI302SpeechModelConfig);
get provider(): string;
/**
* Parse modelId to extract provider and voice
* Format: "provider/voice" or "provider/model/voice"
*/
private parseModelId;
private getArgs;
/**
* Poll for async task completion
*/
private pollForResult;
/**
* Download audio from URL and return as Uint8Array
*/
private downloadAudio;
doGenerate(options: Parameters<SpeechModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV3['doGenerate']>>>;
}
type AI302TranscriptionCallOptions = Omit<TranscriptionModelV3CallOptions, 'providerOptions'> & {
providerOptions?: {
ai302?: AI302TranscriptionProviderOptions;
};
};
interface AI302TranscriptionModelConfig extends AI302Config {
_internal?: {
currentDate?: () => Date;
};
}
declare class AI302TranscriptionModel implements TranscriptionModelV3 {
readonly modelId: AI302TranscriptionModelId;
private readonly config;
readonly specificationVersion = "v3";
get provider(): string;
constructor(modelId: AI302TranscriptionModelId, config: AI302TranscriptionModelConfig);
private getArgs;
doGenerate(options: AI302TranscriptionCallOptions): Promise<Awaited<ReturnType<TranscriptionModelV3['doGenerate']>>>;
/**
* Handle verbose_json response format
*/
private handleVerboseResponse;
/**
* Handle json response format
*/
private handleJsonResponse;
/**
* Handle diarized_json response format (speaker diarization)
*/
private handleDiarizedResponse;
/**
* Handle text/srt/vtt response formats that return raw text
*/
private handleTextResponse;
}
declare const VERSION = "0.1.1";
export { AI302EmbeddingModel, type AI302EmbeddingModelId, type AI302EmbeddingProviderOptions, AI302LanguageModel, type AI302Provider, type AI302ProviderSettings, AI302RerankingModel, type AI302RerankingModelId, type AI302RerankingProviderOptions, AI302SpeechModel, type AI302SpeechModelId, type AI302SpeechProviderOptions, type AI302TTSProvider, AI302TranscriptionModel, type AI302TranscriptionModelId, type AI302TranscriptionProvider, type AI302TranscriptionProviderOptions, type AI302TranscriptionResponseFormat, VERSION, ai302, createAI302 };