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
Properly parse json options for key generation in the UI (#12989)
stellasec47f6984dce00
diff --git a/ui/litellm-dashboard/src/components/common_components/check_openapi_schema.tsx b/ui/litellm-dashboard/src/components/common_components/check_openapi_schema.tsxindex 6f439508d76..2a6eced8848 100644--- a/ui/litellm-dashboard/src/components/common_components/check_openapi_schema.tsx+++ b/ui/litellm-dashboard/src/components/common_components/check_openapi_schema.tsx@@ -33,9 +33,12 @@ interface SchemaFormFieldsProps {defaultValues?: { [key: string]: any };}+// Define which fields should be parsed as JSON+export const jsonFields = ['metadata', 'config', 'enforced_params', 'aliases'];++// Helper function to determine if a field should be treated as JSONconst isJSONField = (key: string, property: SchemaProperty): boolean => {- const jsonFields = ['metadata', 'config', 'enforced_params', 'aliases'];return jsonFields.includes(key) || property.format === 'json';};diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsxindex 2e45b0f9c03..ac045fa1333 100644--- a/ui/litellm-dashboard/src/components/networking.tsx+++ b/ui/litellm-dashboard/src/components/networking.tsx@@ -17,6 +17,7 @@ import {EmailEventSettingsResponse,EmailEventSettingsUpdateRequest,} from "./email_events/types";+import { jsonFields } from "./common_components/check_openapi_schema"const isLocal = process.env.NODE_ENV === "development";export const defaultProxyBaseUrl = isLocal ? "http://localhost:4000" : null;@@ -573,14 +574,16 @@ export const keyCreateServiceAccountCall = async (delete formValues.description;formValues.metadata = JSON.stringify(formValues.metadata);}- // if formValues.metadata is not undefined, make it a valid dict- if (formValues.metadata) {- console.log("formValues.metadata:", formValues.metadata);- // if there's an exception JSON.parse, show it in the message- try {- formValues.metadata = JSON.parse(formValues.metadata);- } catch (error) {- throw new Error("Failed to parse metadata: " + error);+ // Parse JSON fields if they exist+ for (const field of jsonFields) {+ if (formValues[field]) {+ console.log(`formValues.${field}:`, formValues[field]);+ // if there's an exception JSON.parse, show it in the message+ try {+ formValues[field] = JSON.parse(formValues[field]);+ } catch (error) {+ throw new Error(`Failed to parse ${field}: ` + error);+ }}}@@ -624,7 +627,7 @@ export const keyCreateCall = async (// check if formValues.description is not undefined, make it a string and add it to formValues.metadataif (formValues.description) {- // add to formValues.metadata+ // add to formValues.metadatif (!formValues.metadata) {formValues.metadata = {};}@@ -634,14 +637,16 @@ export const keyCreateCall = async (delete formValues.description;formValues.metadata = JSON.stringify(formValues.metadata);}- // if formValues.metadata is not undefined, make it a valid dict- if (formValues.metadata) {- console.log("formValues.metadata:", formValues.metadata);- // if there's an exception JSON.parse, show it in the message- try {- formValues.metadata = JSON.parse(formValues.metadata);- } catch (error) {- throw new Error("Failed to parse metadata: " + error);+ // Parse JSON fields if they exist+ for (const field of jsonFields) {+ if (formValues[field]) {+ console.log(`formValues.${field}:`, formValues[field]);+ // if there's an exception JSON.parse, show it in the message+ try {+ formValues[field] = JSON.parse(formValues[field]);+ } catch (error) {+ throw new Error(`Failed to parse ${field}: ` + error);+ }}}@@ -6431,4 +6436,3 @@ export const vectorStoreSearchCall = async (}};-