The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
feat(credentials.tsx): add modal for adding new credentials
Krrish Dholakiaad11131b6316
diff --git a/ui/litellm-dashboard/src/components/model_add/add_credentials_tab.tsx b/ui/litellm-dashboard/src/components/model_add/add_credentials_tab.tsxnew file mode 100644index 00000000000..244930999a6--- /dev/null+++ b/ui/litellm-dashboard/src/components/model_add/add_credentials_tab.tsx@@ -0,0 +1,149 @@+import React, { useState } from "react";+import {+ Card,+ Form,+ Button,+ Tooltip,+ Typography,+ Select as AntdSelect,+ Input,+ Switch,+ Modal+} from "antd";+import type { UploadProps } from "antd/es/upload";+import { Providers, providerLogoMap } from "../provider_info_helpers";+import type { FormInstance } from "antd";+import ProviderSpecificFields from "../add_model/provider_specific_fields";++const { Title, Link } = Typography;++interface AddCredentialsModalProps {+ isVisible: boolean;+ onCancel: () => void;+ onAddCredential: (values: any) => void;+ uploadProps: UploadProps;+}++const AddCredentialsModal: React.FC<AddCredentialsModalProps> = ({+ isVisible,+ onCancel,+ onAddCredential,+ uploadProps+}) => {+ const [form] = Form.useForm();+ const [selectedProvider, setSelectedProvider] = useState<Providers>(Providers.OpenAI);+ const [showAdvancedSettings, setShowAdvancedSettings] = useState(false);++ const handleSubmit = (values: any) => {+ onAddCredential(values);+ form.resetFields();+ };++ return (+ <Modal+ title="Add New Credential"+ visible={isVisible}+ onCancel={() => {+ onCancel();+ form.resetFields();+ }}+ footer={null}+ width={600}+ >+ <Form+ form={form}+ onFinish={handleSubmit}+ layout="vertical"+ >+ {/* Provider Selection */}+ <Form.Item+ rules={[{ required: true, message: "Required" }]}+ label="Provider:"+ name="custom_llm_provider"+ tooltip="Select the credential provider"+ >+ <AntdSelect+ showSearch={true}+ value={selectedProvider}+ onChange={(value) => {+ setSelectedProvider(value);+ form.setFieldsValue({+ model: [],+ model_name: undefined+ });+ }}+ >+ {Object.entries(Providers).map(([providerEnum, providerDisplayName]) => (+ <AntdSelect.Option+ key={providerEnum}+ value={providerEnum}+ >+ <div className="flex items-center space-x-2">+ <img+ src={providerLogoMap[providerDisplayName]}+ alt={`${providerEnum} logo`}+ className="w-5 h-5"+ onError={(e) => {+ const target = e.target as HTMLImageElement;+ const parent = target.parentElement;+ if (parent) {+ const fallbackDiv = document.createElement('div');+ fallbackDiv.className = 'w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs';+ fallbackDiv.textContent = providerDisplayName.charAt(0);+ parent.replaceChild(fallbackDiv, target);+ }+ }}+ />+ <span>{providerDisplayName}</span>+ </div>+ </AntdSelect.Option>+ ))}+ </AntdSelect>+ </Form.Item>++ {/* Credential Name */}+ <Form.Item+ label="Credential Name:"+ name="credential_name"+ rules={[{ required: true, message: "Credential name is required" }]}+ >+ <Input placeholder="Enter a friendly name for these credentials" />+ </Form.Item>++ <ProviderSpecificFields+ selectedProvider={selectedProvider}+ uploadProps={uploadProps}+ />++ {/* Modal Footer */}+ <div className="flex justify-between items-center">+ <Tooltip title="Get help on our github">+ <Link href="https://github.com/BerriAI/litellm/issues">+ Need Help?+ </Link>+ </Tooltip>++ <div>+ <Button+ onClick={() => {+ onCancel();+ form.resetFields();+ }}+ style={{ marginRight: 10 }}+ >+ Cancel+ </Button>+ <Button+ type="primary"+ htmlType="submit"+ >+ Add Credential+ </Button>+ </div>+ </div>+ </Form>+ </Modal>+ );+};++export default AddCredentialsModal;\ No newline at end of filediff --git a/ui/litellm-dashboard/src/components/model_add/credentials.tsx b/ui/litellm-dashboard/src/components/model_add/credentials.tsxindex 7c32dd72d72..96a69901326 100644--- a/ui/litellm-dashboard/src/components/model_add/credentials.tsx+++ b/ui/litellm-dashboard/src/components/model_add/credentials.tsx@@ -11,11 +11,14 @@ import {Badge,Button} from "@tremor/react";+import { UploadProps } from "antd/es/upload";import { PlusIcon } from "@heroicons/react/solid";import { getCredentialsList } from "@/components/networking"; // Assume this is your networking function-+import AddCredentialsTab from "./add_credentials_tab";+import { Form } from "antd";interface CredentialsPanelProps {accessToken: string | null;+ uploadProps: UploadProps;}interface CredentialsResponse {@@ -37,9 +40,32 @@ interface CredentialItem {};}-const CredentialsPanel: React.FC<CredentialsPanelProps> = ({ accessToken }) => {+const CredentialsPanel: React.FC<CredentialsPanelProps> = ({ accessToken, uploadProps }) => {const [credentialsList, setCredentialsList] = useState<CredentialItem[]>([]);const [isAddModalOpen, setIsAddModalOpen] = useState(false);+ const [form] = Form.useForm();++ const handleAddCredential = (values: any) => {+ // Transform form values into credential structure+ const newCredential = {+ credential_name: values.credential_name,+ provider: values.custom_llm_provider,+ credential_values: {+ api_key: values.api_key,+ api_base: values.api_base+ },+ credential_info: {+ type: values.custom_llm_provider,+ required: true, // You might want to make this configurable+ default: values.credential_name+ }+ };++ // Add to list and close modal+ setCredentialsList([...credentialsList, newCredential]);+ setIsAddModalOpen(false);+ form.resetFields();+ };useEffect(() => {if (!accessToken) {@@ -76,12 +102,6 @@ const CredentialsPanel: React.FC<CredentialsPanelProps> = ({ accessToken }) => {return (<div className="w-full mx-auto flex-auto overflow-y-auto m-8 p-2">- <Button- onClick={() => setIsAddModalOpen(true)}- className="mb-4"- >- Add Credential- </Button><div className="flex justify-between items-center mb-4"><Text>Configured credentials for different AI providers. Add and manage your API credentials.{" "}@@ -136,19 +156,23 @@ const CredentialsPanel: React.FC<CredentialsPanelProps> = ({ accessToken }) => {</TableBody></Table></Card>+ <Button+ onClick={() => setIsAddModalOpen(true)}+ className="mt-4"+ >+ Add Credential+ </Button>- {/* TODO: Implement Add Credential Modal */}{isAddModalOpen && (- <div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center">- {/* Modal content for adding credentials */}- <Button- onClick={() => setIsAddModalOpen(false)}- >- Close- </Button>- </div>+ <AddCredentialsTab+ form={form}+ handleOk={handleAddCredential}+ isVisible={isAddModalOpen}+ onCancel={() => setIsAddModalOpen(false)}+ uploadProps={uploadProps}+ />)}</div>);diff --git a/ui/litellm-dashboard/src/components/model_dashboard.tsx b/ui/litellm-dashboard/src/components/model_dashboard.tsxindex 75036f1f482..12c9c45415c 100644--- a/ui/litellm-dashboard/src/components/model_dashboard.tsx+++ b/ui/litellm-dashboard/src/components/model_dashboard.tsx@@ -1484,7 +1484,7 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({</Button></TabPanel><TabPanel>- <CredentialsPanel accessToken={accessToken} />+ <CredentialsPanel accessToken={accessToken} uploadProps={uploadProps}/></TabPanel></TabPanels></TabGroup>