feat: support 302ai provider (#8362)

*  feat: support 302.AI provider

* 📝 docs: update docs of 302.AI

* 🐛 fix: error 404 of images in ai302.mdx and ai302.zh-CN.mdx

* 🐛 fix: fix issue of failing tests
This commit is contained in:
JI4JUN
2025-08-05 15:50:13 +08:00
committed by GitHub
parent db57461337
commit e172055a52
16 changed files with 465 additions and 2 deletions
+5
View File
@@ -140,6 +140,11 @@ OPENAI_API_KEY=sk-xxxxxxxxx
# INFINIAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
### 302.AI ###
# AI302_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
### ModelScope ###
# MODELSCOPE_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+2
View File
@@ -248,6 +248,8 @@ ENV \
TENCENT_CLOUD_API_KEY="" TENCENT_CLOUD_MODEL_LIST="" \
# Infini-AI
INFINIAI_API_KEY="" INFINIAI_MODEL_LIST=""
# 302.AI
AI302_API_KEY="" AI302_MODEL_LIST=""
USER nextjs
+3 -1
View File
@@ -289,7 +289,9 @@ ENV \
# Tencent Cloud
TENCENT_CLOUD_API_KEY="" TENCENT_CLOUD_MODEL_LIST="" \
# Infini-AI
INFINIAI_API_KEY="" INFINIAI_MODEL_LIST=""
INFINIAI_API_KEY="" INFINIAI_MODEL_LIST="" \
# 302.AI
AI302_API_KEY="" AI302_MODEL_LIST=""
USER nextjs
+3 -1
View File
@@ -245,7 +245,9 @@ ENV \
# Tencent Cloud
TENCENT_CLOUD_API_KEY="" TENCENT_CLOUD_MODEL_LIST="" \
# Infini-AI
INFINIAI_API_KEY="" INFINIAI_MODEL_LIST=""
INFINIAI_API_KEY="" INFINIAI_MODEL_LIST="" \
# 302.AI
AI302_API_KEY="" AI302_MODEL_LIST=""
USER nextjs
+45
View File
@@ -0,0 +1,45 @@
---
title: Using 302.AI in LobeChat
description: Learn how to configure and use 302.AI's API Key in LobeChat to start conversations and interactions.
tags:
- LobeChat
- 302.AI
- API Key
- Web UI
---
# Using 302.AI in LobeChat
<Image cover src={'https://file.302.ai/gpt/imgs/20250722/c7a6ee9959a8490fa00481dae0fbb339.jpg'} />
[302.AI](https://www.302.ai/) is a pay-as-you-go AI application platform that provides the most comprehensive AI APIs and AI online applications on the market.
This article will guide you on how to use 302.AI in LobeChat.
<Steps>
### Step 1: Obtain [302.AI](https://www.302.ai/) API Key
- Click `Get Started`, register and log in to [302.AI](https://www.302.ai/)
- Click `API Keys` on the left side
- Click `Add API KEY`, copy and save the generated API key
<Image alt={'Get API Key'} inStep src={'https://file.302.ai/gpt/imgs/20250722/7a3597061d9a484ca7358867930a8316.jpg'} />
### Step 2: Configure 302.AI in LobeChat
- Access LobeChat's `Settings` interface
- Find the `302.AI` configuration item under `Language Models`
<Image alt={'Enter API Key'} inStep src={'https://file.302.ai/gpt/imgs/20250722/b056ca4e63374668b7e3e093726fa6f0.jpg'} />
- Enter the obtained API key
- Select a 302.AI model for your AI assistant to start conversations
<Image alt={'Select 302.AI model and start conversation'} inStep src={'https://file.302.ai/gpt/imgs/20250722/c7a6ee9959a8490fa00481dae0fbb339.jpg'} />
<Callout type={'warning'}>
During usage, you may need to pay the API service provider. Please refer to 302.AI's relevant pricing policy.
</Callout>
</Steps>
Now you can use 302.AI's models for conversations in LobeChat.
+45
View File
@@ -0,0 +1,45 @@
---
title: 在 LobeChat 中使用 302.AI
description: 学习如何在 LobeChat 中配置和使用 302.AI 的API Key,以便开始对话和交互。
tags:
- LobeChat
- 302.AI
- API密钥
- Web UI
---
# 在 LobeChat 中使用 302.AI
<Image cover src={'https://file.302.ai/gpt/imgs/20250722/d346c796faa4443eb0bd4218f84205f6.jpg'} />
[302.AI](https://www.302.ai/) 是一个按需付费的 AI 应用平台,提供市面上最全的 AI API 和 AI 在线应用。
本文将指导你如何在 LobeChat 中使用 302.AI。
<Steps>
### 步骤一:获得 [302.AI](https://www.302.ai/) 的 API Key
- 点击 `开始使用`,注册并登录 [302.AI](https://www.302.ai/)
- 点击左侧的 `API Keys`
- 点击 `添加API KEY`,复制并保存生成的 API 密钥
<Image alt={'获取 API 密钥'} inStep src={'https://file.302.ai/gpt/imgs/20250722/01abd69fd61540489781fd963e504a04.jpg'} />
### 步骤二:在 LobeChat 中配置 302.AI
- 访问 LobeChat 的`设置`界面
- 在`语言模型`下找到 `302.AI` 的设置项
<Image alt={'填入 API 密钥'} inStep src={'https://file.302.ai/gpt/imgs/20250722/5247463e74c742f79bef416bbb0722bf.jpg'} />
- 填入获得的 API 密钥
- 为你的 AI 助手选择一个 302.AI 的模型即可开始对话
<Image alt={'选择 302.AI 模型并开始对话'} inStep src={'https://file.302.ai/gpt/imgs/20250722/d346c796faa4443eb0bd4218f84205f6.jpg'} />
<Callout type={'warning'}>
在使用过程中你可能需要向 API 服务提供商付费,请参考 302.AI 的相关费用政策。
</Callout>
</Steps>
至此你已经可以在 LobeChat 中使用 302.AI 提供的模型进行对话了。
@@ -38,6 +38,7 @@ export interface SearchEngineKeyVaults {
export interface UserKeyVaults extends SearchEngineKeyVaults {
ai21?: OpenAICompatibleKeyVault;
ai302?: OpenAICompatibleKeyVault;
ai360?: OpenAICompatibleKeyVault;
aihubmix?: OpenAICompatibleKeyVault;
anthropic?: OpenAICompatibleKeyVault;
@@ -2,6 +2,7 @@ import { useMemo } from 'react';
import {
Ai21ProviderCard,
Ai302ProviderCard,
Ai360ProviderCard,
AnthropicProviderCard,
BaichuanProviderCard,
@@ -112,6 +113,7 @@ export const useProviderList = (): ProviderItem[] => {
GiteeAIProviderCard,
PPIOProviderCard,
InfiniAIProviderCard,
Ai302ProviderCard,
],
[
AzureProvider,
+148
View File
@@ -0,0 +1,148 @@
import { AIChatModelCard } from '@/types/aiModel';
const ai302ChatModels: AIChatModelCard[] = [
{
contextWindowTokens: 32_000,
displayName: 'deepseek-chat',
enabled: true,
id: 'deepseek-chat',
type: 'chat',
},
{
contextWindowTokens: 128_000,
displayName: 'chatgpt-4o-latest',
enabled: true,
id: 'chatgpt-4o-latest',
type: 'chat',
},
{
contextWindowTokens: 128_000,
displayName: 'llama3.3-70b',
enabled: true,
id: 'llama3.3-70b',
type: 'chat',
},
{
contextWindowTokens: 64_000,
displayName: 'deepseek-reasoner',
enabled: true,
id: 'deepseek-reasoner',
type: 'chat',
},
{
contextWindowTokens: 1_000_000,
displayName: 'gemini-2.0-flash',
enabled: true,
id: 'gemini-2.0-flash',
type: 'chat',
},
{
contextWindowTokens: 200_000,
displayName: 'claude-3-7-sonnet-20250219',
enabled: true,
id: 'claude-3-7-sonnet-20250219',
type: 'chat',
},
{
contextWindowTokens: 200_000,
displayName: 'claude-3-7-sonnet-latest',
enabled: true,
id: 'claude-3-7-sonnet-latest',
type: 'chat',
},
{
contextWindowTokens: 131_072,
displayName: 'grok-3-beta',
enabled: true,
id: 'grok-3-beta',
type: 'chat',
},
{
contextWindowTokens: 131_072,
displayName: 'grok-3-mini-beta',
enabled: true,
id: 'grok-3-mini-beta',
type: 'chat',
},
{
contextWindowTokens: 1_000_000,
displayName: 'gpt-4.1',
enabled: true,
id: 'gpt-4.1',
type: 'chat',
},
{
contextWindowTokens: 200_000,
displayName: 'o3',
enabled: true,
id: 'o3',
type: 'chat',
},
{
contextWindowTokens: 200_000,
displayName: 'o4-mini',
enabled: true,
id: 'o4-mini',
type: 'chat',
},
{
contextWindowTokens: 128_000,
displayName: 'qwen3-235b-a22b',
enabled: true,
id: 'qwen3-235b-a22b',
type: 'chat',
},
{
contextWindowTokens: 128_000,
displayName: 'qwen3-32b',
enabled: true,
id: 'qwen3-32b',
type: 'chat',
},
{
contextWindowTokens: 1_000_000,
displayName: 'gemini-2.5-pro-preview-05-06',
enabled: true,
id: 'gemini-2.5-pro-preview-05-06',
type: 'chat',
},
{
contextWindowTokens: 128_000,
displayName: 'llama-4-maverick',
enabled: true,
id: 'llama-4-maverick',
type: 'chat',
},
{
contextWindowTokens: 1_000_000,
displayName: 'gemini-2.5-flash',
enabled: true,
id: 'gemini-2.5-flash',
type: 'chat',
},
{
contextWindowTokens: 200_000,
displayName: 'claude-sonnet-4-20250514',
enabled: true,
id: 'claude-sonnet-4-20250514',
type: 'chat',
},
{
contextWindowTokens: 200_000,
displayName: 'claude-opus-4-20250514',
enabled: true,
id: 'claude-opus-4-20250514',
type: 'chat',
},
{
contextWindowTokens: 1_000_000,
displayName: 'gemini-2.5-pro',
enabled: true,
id: 'gemini-2.5-pro',
type: 'chat',
},
];
export const allModels = [...ai302ChatModels];
export default allModels;
+3
View File
@@ -1,6 +1,7 @@
import { AiFullModelCard, LobeDefaultAiModelListItem } from '@/types/aiModel';
import { default as ai21 } from './ai21';
import { default as ai302 } from './ai302';
import { default as ai360 } from './ai360';
import { default as aihubmix } from './aihubmix';
import { default as anthropic } from './anthropic';
@@ -78,6 +79,7 @@ const buildDefaultModelList = (map: ModelsMap): LobeDefaultAiModelListItem[] =>
export const LOBE_DEFAULT_MODEL_LIST = buildDefaultModelList({
ai21,
ai302,
ai360,
aihubmix,
anthropic,
@@ -136,6 +138,7 @@ export const LOBE_DEFAULT_MODEL_LIST = buildDefaultModelList({
});
export { default as ai21 } from './ai21';
export { default as ai302 } from './ai302';
export { default as ai360 } from './ai360';
export { default as aihubmix } from './aihubmix';
export { default as anthropic } from './anthropic';
+7
View File
@@ -172,6 +172,10 @@ export const getLLMConfig = () => {
ENABLED_V0: z.boolean(),
V0_API_KEY: z.string().optional(),
ENABLED_AI302: z.boolean(),
AI302_API_KEY: z.string().optional(),
ENABLED_AIHUBMIX: z.boolean(),
AIHUBMIX_API_KEY: z.string().optional(),
},
@@ -344,6 +348,9 @@ export const getLLMConfig = () => {
ENABLED_V0: !!process.env.V0_API_KEY,
V0_API_KEY: process.env.V0_API_KEY,
ENABLED_AI302: !!process.env.AI302_API_KEY,
AI302_API_KEY: process.env.AI302_API_KEY,
ENABLED_AIHUBMIX: !!process.env.AIHUBMIX_API_KEY,
AIHUBMIX_API_KEY: process.env.AIHUBMIX_API_KEY,
},
+149
View File
@@ -0,0 +1,149 @@
import { ModelProviderCard } from '@/types/llm';
// ref: https://302.ai/pricing/
const Ai302: ModelProviderCard = {
chatModels: [
{
contextWindowTokens: 32_000,
displayName: 'deepseek-chat',
enabled: true,
id: 'deepseek-chat',
},
{
contextWindowTokens: 128_000,
displayName: 'gpt-4o',
enabled: true,
id: 'gpt-4o',
},
{
contextWindowTokens: 128_000,
displayName: 'chatgpt-4o-latest',
enabled: true,
id: 'chatgpt-4o-latest',
},
{
contextWindowTokens: 128_000,
displayName: 'llama3.3-70b',
enabled: true,
id: 'llama3.3-70b',
},
{
contextWindowTokens: 64_000,
displayName: 'deepseek-reasoner',
enabled: true,
id: 'deepseek-reasoner',
},
{
contextWindowTokens: 1_000_000,
displayName: 'gemini-2.0-flash',
enabled: true,
id: 'gemini-2.0-flash',
},
{
contextWindowTokens: 200_000,
displayName: 'claude-3-7-sonnet-20250219',
enabled: true,
id: 'claude-3-7-sonnet-20250219',
},
{
contextWindowTokens: 200_000,
displayName: 'claude-3-7-sonnet-latest',
enabled: true,
id: 'claude-3-7-sonnet-latest',
},
{
contextWindowTokens: 131_072,
displayName: 'grok-3-beta',
enabled: true,
id: 'grok-3-beta',
},
{
contextWindowTokens: 131_072,
displayName: 'grok-3-mini-beta',
enabled: true,
id: 'grok-3-mini-beta',
},
{
contextWindowTokens: 1_000_000,
displayName: 'gpt-4.1',
enabled: true,
id: 'gpt-4.1',
},
{
contextWindowTokens: 200_000,
displayName: 'o3',
enabled: true,
id: 'o3',
},
{
contextWindowTokens: 200_000,
displayName: 'o4-mini',
enabled: true,
id: 'o4-mini',
},
{
contextWindowTokens: 128_000,
displayName: 'qwen3-235b-a22b',
enabled: true,
id: 'qwen3-235b-a22b',
},
{
contextWindowTokens: 128_000,
displayName: 'qwen3-32b',
enabled: true,
id: 'qwen3-32b',
},
{
contextWindowTokens: 1_000_000,
displayName: 'gemini-2.5-pro-preview-05-06',
enabled: true,
id: 'gemini-2.5-pro-preview-05-06',
},
{
contextWindowTokens: 128_000,
displayName: 'llama-4-maverick',
enabled: true,
id: 'llama-4-maverick',
},
{
contextWindowTokens: 1_000_000,
displayName: 'gemini-2.5-flash',
enabled: true,
id: 'gemini-2.5-flash',
},
{
contextWindowTokens: 200_000,
displayName: 'claude-sonnet-4-20250514',
enabled: true,
id: 'claude-sonnet-4-20250514',
},
{
contextWindowTokens: 200_000,
displayName: 'claude-opus-4-20250514',
enabled: true,
id: 'claude-opus-4-20250514',
},
{
contextWindowTokens: 1_000_000,
displayName: 'gemini-2.5-pro',
enabled: true,
id: 'gemini-2.5-pro',
},
],
checkModel: 'gpt-4o',
description: '302.AI 是一个按需付费的 AI 应用平台,提供市面上最全的 AI API 和 AI 在线应用',
id: 'ai302',
modelList: { showModelFetcher: true },
modelsUrl: 'https://302.ai/pricing/',
name: '302.AI',
settings: {
proxyUrl: {
placeholder: 'https://api.302.ai/v1',
},
sdkType: 'openai',
showModelFetcher: true,
},
url: 'https://302.ai',
};
export default Ai302;
+3
View File
@@ -1,6 +1,7 @@
import { ChatModelCard, ModelProviderCard } from '@/types/llm';
import Ai21Provider from './ai21';
import Ai302Provider from './ai302';
import Ai360Provider from './ai360';
import AiHubMixProvider from './aihubmix';
import AnthropicProvider from './anthropic';
@@ -169,6 +170,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [
Search1APIProvider,
InfiniAIProvider,
QiniuProvider,
Ai302Provider,
];
export const filterEnabledModels = (provider: ModelProviderCard) => {
@@ -181,6 +183,7 @@ export const isProviderDisableBrowserRequest = (id: string) => {
};
export { default as Ai21ProviderCard } from './ai21';
export { default as Ai302ProviderCard } from './ai302';
export { default as Ai360ProviderCard } from './ai360';
export { default as AiHubMixProviderCard } from './aihubmix';
export { default as AnthropicProviderCard } from './anthropic';
+46
View File
@@ -0,0 +1,46 @@
import { AgentRuntimeErrorType } from '../error';
import { ChatCompletionErrorPayload, ModelProvider } from '../types';
import { processMultiProviderModelList } from '../utils/modelParse';
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
export interface Ai302ModelCard {
id: string;
}
export const Lobe302AI = createOpenAICompatibleRuntime({
baseURL: 'https://api.302.ai/v1',
chatCompletion: {
handleError: (error: any): Omit<ChatCompletionErrorPayload, 'provider'> | undefined => {
let errorResponse: Response | undefined;
if (error instanceof Response) {
errorResponse = error;
} else if ('status' in (error as any)) {
errorResponse = error as Response;
}
if (errorResponse && errorResponse.status === 401) {
return {
error: errorResponse.status,
errorType: AgentRuntimeErrorType.InvalidProviderAPIKey,
};
}
return {
error,
};
},
},
debug: {
chatCompletion: () => process.env.DEBUG_SILICONCLOUD_CHAT_COMPLETION === '1',
},
errorType: {
bizError: AgentRuntimeErrorType.ProviderBizError,
invalidAPIKey: AgentRuntimeErrorType.InvalidProviderAPIKey,
},
models: async ({ client }) => {
const modelsPage = (await client.models.list()) as any;
const modelList: Ai302ModelCard[] = modelsPage.data;
return processMultiProviderModelList(modelList);
},
provider: ModelProvider.Ai302,
});
+2
View File
@@ -1,4 +1,5 @@
import { LobeAi21AI } from './ai21';
import { Lobe302AI } from './ai302';
import { LobeAi360AI } from './ai360';
import { LobeAiHubMixAI } from './aihubmix';
import { LobeAnthropicAI } from './anthropic';
@@ -56,6 +57,7 @@ import { LobeZhipuAI } from './zhipu';
export const providerRuntimeMap = {
ai21: LobeAi21AI,
ai302: Lobe302AI,
ai360: LobeAi360AI,
aihubmix: LobeAiHubMixAI,
anthropic: LobeAnthropicAI,
+1
View File
@@ -29,6 +29,7 @@ export interface CreateChatCompletionOptions {
export enum ModelProvider {
Ai21 = 'ai21',
Ai302 = 'ai302',
Ai360 = 'ai360',
AiHubMix = 'aihubmix',
Anthropic = 'anthropic',