Skip to content

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]

Litellm UI API Reference page updates (#15438)

Achintya Rajan6b66e12deabd
diff --git a/ui/litellm-dashboard/package-lock.json b/ui/litellm-dashboard/package-lock.json
index 5e85b773534..a28a2eb344d 100644
--- a/ui/litellm-dashboard/package-lock.json
+++ b/ui/litellm-dashboard/package-lock.json
@@ -33,7 +33,7 @@
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18",
"react-markdown": "^9.0.1",
- "react-syntax-highlighter": "^15.6.1",
+ "react-syntax-highlighter": "^15.6.6",
"tailwind-merge": "^3.2.0",
"uuid": "^11.1.0"
},
@@ -19097,15 +19097,15 @@
}
},
"node_modules/react-syntax-highlighter": {
- "version": "15.6.1",
- "resolved": "https://registry.npmjs.org/react-syntax-highlighter/-/react-syntax-highlighter-15.6.1.tgz",
- "integrity": "sha512-OqJ2/vL7lEeV5zTJyG7kmARppUjiB9h9udl4qHQjjgEos66z00Ia0OckwYfRxCSFrW8RJIBnsBwQsHZbVPspqg==",
+ "version": "15.6.6",
+ "resolved": "https://registry.npmjs.org/react-syntax-highlighter/-/react-syntax-highlighter-15.6.6.tgz",
+ "integrity": "sha512-DgXrc+AZF47+HvAPEmn7Ua/1p10jNoVZVI/LoPiYdtY+OM+/nG5yefLHKJwdKqY1adMuHFbeyBaG9j64ML7vTw==",
"dependencies": {
"@babel/runtime": "^7.3.1",
"highlight.js": "^10.4.1",
"highlightjs-vue": "^1.0.0",
"lowlight": "^1.17.0",
- "prismjs": "^1.27.0",
+ "prismjs": "^1.30.0",
"refractor": "^3.6.0"
},
"peerDependencies": {
diff --git a/ui/litellm-dashboard/package.json b/ui/litellm-dashboard/package.json
index 5578a9f2f39..4746b893545 100644
--- a/ui/litellm-dashboard/package.json
+++ b/ui/litellm-dashboard/package.json
@@ -38,7 +38,7 @@
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18",
"react-markdown": "^9.0.1",
- "react-syntax-highlighter": "^15.6.1",
+ "react-syntax-highlighter": "^15.6.6",
"tailwind-merge": "^3.2.0",
"uuid": "^11.1.0"
},
diff --git a/ui/litellm-dashboard/src/components/api_ref.tsx b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/APIReferenceView.tsx
similarity index 68%
rename from ui/litellm-dashboard/src/components/api_ref.tsx
rename to ui/litellm-dashboard/src/app/(dashboard)/api-reference/APIReferenceView.tsx
index 8876c414c0b..ba2596b92c3 100644
--- a/ui/litellm-dashboard/src/components/api_ref.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/APIReferenceView.tsx
@@ -1,35 +1,32 @@
"use client";
import React from "react";
-import {
- Text,
- Tab,
- TabGroup,
- TabList,
- TabPanel,
- TabPanels,
- Grid,
-} from "@tremor/react";
-import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
+import { Text, Tab, TabGroup, TabList, TabPanel, TabPanels, Grid } from "@tremor/react";
+import CodeBlock from "./components/CodeBlock";
+import DocLink from "@/app/(dashboard)/api-reference/components/DocLink";
interface ApiRefProps {
proxySettings: any;
}
-const APIRef: React.FC<ApiRefProps> = ({ proxySettings }) => {
+const APIReferenceView: React.FC<ApiRefProps> = ({ proxySettings }) => {
let base_url = "<your_proxy_base_url>";
- if (proxySettings) {
- if (proxySettings.PROXY_BASE_URL && proxySettings.PROXY_BASE_URL !== undefined) {
- base_url = proxySettings.PROXY_BASE_URL;
- }
+ if (proxySettings?.PROXY_BASE_URL !== undefined && proxySettings?.PROXY_BASE_URL) {
+ base_url = proxySettings.PROXY_BASE_URL;
}
+
return (
<>
<Grid className="gap-2 p-8 h-[80vh] w-full mt-2">
<div className="mb-5">
- <p className="text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold">
- OpenAI Compatible Proxy: API Reference
- </p>
+ {/* Header row with Docs link on the right */}
+ <div className="flex items-center justify-between">
+ <p className="text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold">
+ OpenAI Compatible Proxy: API Reference
+ </p>
+ <DocLink className="ml-3 shrink-0" href="https://docs.litellm.ai/docs/proxy/user_keys" />
+ </div>
+
<Text className="mt-2 mb-2">
LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url
to point to your litellm proxy. Example Below{" "}
@@ -43,9 +40,9 @@ const APIRef: React.FC<ApiRefProps> = ({ proxySettings }) => {
</TabList>
<TabPanels>
<TabPanel>
- <SyntaxHighlighter language="python">
- {`
-import openai
+ <CodeBlock
+ language="python"
+ code={`import openai
client = openai.OpenAI(
api_key="your_api_key",
base_url="${base_url}" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys
@@ -61,14 +58,14 @@ response = client.chat.completions.create(
]
)
-print(response)
- `}
- </SyntaxHighlighter>
+print(response)`}
+ />
</TabPanel>
+
<TabPanel>
- <SyntaxHighlighter language="python">
- {`
-import os, dotenv
+ <CodeBlock
+ language="python"
+ code={`import os, dotenv
from llama_index.llms import AzureOpenAI
from llama_index.embeddings import AzureOpenAIEmbedding
@@ -89,22 +86,20 @@ embed_model = AzureOpenAIEmbedding(
api_version="2023-07-01-preview",
)
-
documents = SimpleDirectoryReader("llama_index_data").load_data()
service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)
index = VectorStoreIndex.from_documents(documents, service_context=service_context)
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
-print(response)
-
- `}
- </SyntaxHighlighter>
+print(response)`}
+ />
</TabPanel>
+
<TabPanel>
- <SyntaxHighlighter language="python">
- {`
-from langchain.chat_models import ChatOpenAI
+ <CodeBlock
+ language="python"
+ code={`from langchain.chat_models import ChatOpenAI
from langchain.prompts.chat import (
ChatPromptTemplate,
HumanMessagePromptTemplate,
@@ -128,10 +123,8 @@ messages = [
]
response = chat(messages)
-print(response)
-
- `}
- </SyntaxHighlighter>
+print(response)`}
+ />
</TabPanel>
</TabPanels>
</TabGroup>
@@ -141,4 +134,4 @@ print(response)
);
};
-export default APIRef;
+export default APIReferenceView;
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/api-reference/components/CodeBlock.tsx b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/components/CodeBlock.tsx
new file mode 100644
index 00000000000..8d2fa8acb5d
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/components/CodeBlock.tsx
@@ -0,0 +1,46 @@
+import { useState } from "react";
+import { CheckIcon, ClipboardIcon } from "lucide-react";
+import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
+import { oneLight } from "react-syntax-highlighter/dist/esm/styles/prism";
+
+interface CodeBlockProps {
+ code: string;
+ language: string;
+}
+
+const CodeBlock = ({ code, language }: CodeBlockProps) => {
+ const [copied, setCopied] = useState(false);
+ const copyToClipboard = () => {
+ navigator.clipboard.writeText(code);
+ setCopied(true);
+ setTimeout(() => setCopied(false), 2000);
+ };
+
+ return (
+ <div className="relative rounded-lg border border-gray-200 overflow-hidden">
+ <button
+ onClick={copyToClipboard}
+ className="absolute top-3 right-3 p-2 rounded-md bg-gray-100 hover:bg-gray-200 text-gray-600 z-10"
+ aria-label="Copy code"
+ >
+ {copied ? <CheckIcon size={16} /> : <ClipboardIcon size={16} />}
+ </button>
+ <SyntaxHighlighter
+ language={language}
+ style={oneLight}
+ customStyle={{
+ margin: 0,
+ padding: "1.5rem",
+ borderRadius: "0.5rem",
+ fontSize: "0.9rem",
+ backgroundColor: "#fafafa",
+ }}
+ showLineNumbers
+ >
+ {code}
+ </SyntaxHighlighter>
+ </div>
+ );
+};
+
+export default CodeBlock;
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/api-reference/components/DocLink.tsx b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/components/DocLink.tsx
new file mode 100644
index 00000000000..a3d0416053e
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/components/DocLink.tsx
@@ -0,0 +1,33 @@
+import React from "react";
+import { ExternalLink } from "lucide-react";
+
+function cn(...parts: Array<string | undefined>) {
+ return parts.filter(Boolean).join(" ");
+}
+
+export type DocLinkProps = {
+ href?: string;
+ className?: string;
+};
+
+const DocLink = ({ href, className }: DocLinkProps) => {
+ return (
+ <a
+ href={href}
+ target="_blank"
+ rel="noopener noreferrer"
+ title="Open documentation in a new tab"
+ className={cn(
+ "inline-flex items-center gap-2 rounded-xl border border-zinc-200 bg-white/80 px-3.5 py-2 text-sm font-medium text-zinc-700 shadow-sm",
+ "hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 active:translate-y-[0.5px]",
+ className,
+ )}
+ >
+ <span>API Reference Docs</span>
+ <ExternalLink aria-hidden className="h-4 w-4 opacity-80" />
+ <span className="sr-only">(opens in a new tab)</span>
+ </a>
+ );
+};
+
+export default DocLink;
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/api-reference/page.tsx b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/page.tsx
index 265a6d81954..87a342c2840 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/api-reference/page.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/page.tsx
@@ -1,6 +1,6 @@
"use client";
-import APIRef from "@/components/api_ref";
+import APIReferenceView from "@/app/(dashboard)/api-reference/APIReferenceView";
import { useState } from "react";
interface ProxySettings {
@@ -11,7 +11,7 @@ interface ProxySettings {
const APIReferencePage = () => {
const [proxySettings, setProxySettings] = useState<ProxySettings>({ PROXY_BASE_URL: "", PROXY_LOGOUT_URL: "" });
- return <APIRef proxySettings={proxySettings} />;
+ return <APIReferenceView proxySettings={proxySettings} />;
};
export default APIReferencePage;
diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx
index 19f0dabe45f..32996fea769 100644
--- a/ui/litellm-dashboard/src/app/page.tsx
+++ b/ui/litellm-dashboard/src/app/page.tsx
@@ -20,7 +20,7 @@ import BudgetPanel from "@/components/budgets/budget_panel";
import SpendLogsTable from "@/components/view_logs";
import ModelHubTable from "@/components/model_hub_table";
import NewUsagePage from "@/components/new_usage";
-import APIRef from "@/components/api_ref";
+import APIReferenceView from "@/app/(dashboard)/api-reference/APIReferenceView";
import ChatUI from "@/components/chat_ui/ChatUI";
import Usage from "@/components/usage";
import CacheDashboard from "@/components/cache_dashboard";
@@ -406,7 +406,7 @@ export default function CreateKeyPage() {
proxySettings={proxySettings}
/>
) : page == "api_ref" ? (
- <APIRef proxySettings={proxySettings} />
+ <APIReferenceView proxySettings={proxySettings} />
) : page == "settings" ? (
<Settings userID={userID} userRole={userRole} accessToken={accessToken} premiumUser={premiumUser} />
) : page == "budgets" ? (