Skip to content

Commit ce602ce

Browse files
author
Theodore Li
committed
Add hugging face hosted key
1 parent 945f7ea commit ce602ce

File tree

4 files changed

+125
-1
lines changed
  • apps/sim
    • app
      • api/workspaces/[id]/byok-keys
      • workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/byok
    • blocks/blocks
    • tools/huggingface

4 files changed

+125
-1
lines changed

apps/sim/app/api/workspaces/[id]/byok-keys/route.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,23 @@ import { getUserEntityPermissions, getWorkspaceById } from '@/lib/workspaces/per
1313

1414
const logger = createLogger('WorkspaceBYOKKeysAPI')
1515

16-
const VALID_PROVIDERS = ['openai', 'anthropic', 'google', 'mistral', 'exa'] as const
16+
const VALID_PROVIDERS = [
17+
'openai',
18+
'anthropic',
19+
'google',
20+
'mistral',
21+
'exa',
22+
'huggingface',
23+
'tavily',
24+
'linkup',
25+
'perplexity',
26+
'zep',
27+
'jina',
28+
'google_cloud',
29+
'ahrefs',
30+
'apify',
31+
'elevenlabs',
32+
] as const
1733

1834
const UpsertKeySchema = z.object({
1935
providerId: z.enum(VALID_PROVIDERS),

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/byok/byok.tsx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,24 @@ import {
1414
ModalHeader,
1515
} from '@/components/emcn'
1616
import {
17+
AhrefsIcon,
1718
AnthropicIcon,
19+
ApifyIcon,
1820
BrowserUseIcon,
21+
ElevenLabsIcon,
1922
ExaAIIcon,
2023
FirecrawlIcon,
2124
GeminiIcon,
25+
GoogleIcon,
26+
HuggingFaceIcon,
27+
JinaAIIcon,
28+
LinkupIcon,
2229
MistralIcon,
2330
OpenAIIcon,
31+
PerplexityIcon,
2432
SerperIcon,
33+
TavilyIcon,
34+
ZepIcon,
2535
} from '@/components/icons'
2636
import { Skeleton } from '@/components/ui'
2737
import {
@@ -97,6 +107,76 @@ const PROVIDERS: {
97107
description: 'Web scraping, crawling, and data extraction',
98108
placeholder: 'Enter your Firecrawl API key',
99109
},
110+
{
111+
id: 'huggingface',
112+
name: 'Hugging Face',
113+
icon: HuggingFaceIcon,
114+
description: 'Inference API for chat completions',
115+
placeholder: 'Enter your Hugging Face API token',
116+
},
117+
{
118+
id: 'linkup',
119+
name: 'Linkup',
120+
icon: LinkupIcon,
121+
description: 'Web search and content retrieval',
122+
placeholder: 'Enter your Linkup API key',
123+
},
124+
{
125+
id: 'tavily',
126+
name: 'Tavily',
127+
icon: TavilyIcon,
128+
description: 'AI-powered web search and content extraction',
129+
placeholder: 'Enter your Tavily API key',
130+
},
131+
{
132+
id: 'perplexity',
133+
name: 'Perplexity',
134+
icon: PerplexityIcon,
135+
description: 'AI-powered chat and web search',
136+
placeholder: 'pplx-...',
137+
},
138+
{
139+
id: 'zep',
140+
name: 'Zep',
141+
icon: ZepIcon,
142+
description: 'Long-term memory for AI agents',
143+
placeholder: 'Enter your Zep API key',
144+
},
145+
{
146+
id: 'ahrefs',
147+
name: 'Ahrefs',
148+
icon: AhrefsIcon,
149+
description: 'SEO analysis, backlinks, and keyword research',
150+
placeholder: 'Enter your Ahrefs API key',
151+
},
152+
{
153+
id: 'jina',
154+
name: 'Jina AI',
155+
icon: JinaAIIcon,
156+
description: 'Web reading and search',
157+
placeholder: 'jina_...',
158+
},
159+
{
160+
id: 'elevenlabs',
161+
name: 'ElevenLabs',
162+
icon: ElevenLabsIcon,
163+
description: 'Text-to-speech generation',
164+
placeholder: 'Enter your ElevenLabs API key',
165+
},
166+
{
167+
id: 'google_cloud',
168+
name: 'Google Cloud',
169+
icon: GoogleIcon,
170+
description: 'Translate, Maps, PageSpeed, and Books APIs',
171+
placeholder: 'Enter your Google Cloud API key',
172+
},
173+
{
174+
id: 'apify',
175+
name: 'Apify',
176+
icon: ApifyIcon,
177+
description: 'Web scraping, automation, and actor execution',
178+
placeholder: 'Enter your Apify API token',
179+
},
100180
]
101181

102182
function BYOKKeySkeleton() {

apps/sim/blocks/blocks/huggingface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const HuggingFaceBlock: BlockConfig<HuggingFaceChatResponse> = {
8181
required: true,
8282
placeholder: 'Enter your Hugging Face API token',
8383
password: true,
84+
hideWhenHosted: true,
8485
},
8586
],
8687
tools: {

apps/sim/tools/huggingface/chat.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,33 @@ export const chatTool: ToolConfig<HuggingFaceChatParams, HuggingFaceChatResponse
1212
description: 'Generate completions using Hugging Face Inference API',
1313
version: '1.0',
1414

15+
hosting: {
16+
envKeyPrefix: 'HUGGINGFACE_API_KEY',
17+
apiKeyParam: 'apiKey',
18+
byokProviderId: 'huggingface',
19+
pricing: {
20+
type: 'custom',
21+
getCost: (_params, output) => {
22+
const usage = output.usage as
23+
| { prompt_tokens?: number; completion_tokens?: number; total_tokens?: number }
24+
| undefined
25+
if (!usage || usage.total_tokens == null) {
26+
throw new Error('Hugging Face response missing token usage data')
27+
}
28+
// HF passes through provider costs; ~$3/1M tokens average across routed providers
29+
// https://huggingface.co/docs/api-inference/rate-limits
30+
const totalTokens = usage.total_tokens
31+
const cost = (totalTokens / 1_000_000) * 3
32+
return { cost, metadata: { promptTokens: usage.prompt_tokens, completionTokens: usage.completion_tokens, totalTokens } }
33+
},
34+
},
35+
rateLimit: {
36+
mode: 'per_request',
37+
requestsPerMinute: 60,
38+
},
39+
skipFixedUsageLog: true,
40+
},
41+
1542
params: {
1643
systemPrompt: {
1744
type: 'string',

0 commit comments

Comments
 (0)