Skip to content

Runtime API Examples

This page demonstrates usage of some of the runtime APIs provided by VitePress.

The main useData() API can be used to access site, theme, and page data for the current page. It works in both .md and .vue files:

md
<script setup>
import { useData } from 'vitepress'

const { theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data
<pre>{{ theme }}</pre>

### Page Data
<pre>{{ page }}</pre>

### Page Frontmatter
<pre>{{ frontmatter }}</pre>

Results

Theme Data

{
  "logo": "/logo.png",
  "search": {
    "provider": "local"
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "APP",
      "items": [
        {
          "text": "deepwiki",
          "link": "https://deepwiki.com"
        }
      ]
    },
    {
      "text": "LLM",
      "link": "/llm"
    },
    {
      "text": "Agent",
      "link": "/agent"
    },
    {
      "text": "Eval",
      "link": "/eval"
    },
    {
      "text": "Prompt",
      "link": "/tutorial"
    },
    {
      "text": "MCP",
      "items": [
        {
          "text": "Protocol",
          "link": "https://modelcontextprotocol.io/introduction"
        },
        {
          "text": "Python-SDK",
          "link": "https://deepwiki.com/modelcontextprotocol/python-sdk/"
        }
      ]
    },
    {
      "text": "Tutorial",
      "link": "/tutorial"
    },
    {
      "text": "Docs",
      "items": [
        {
          "text": "OpenAI",
          "link": "/docs/openai/guides"
        },
        {
          "text": "Anthropic",
          "link": "/docs/anthropic"
        },
        {
          "text": "Vitepress",
          "link": "/docs/examples/vitepress"
        }
      ]
    },
    {
      "text": "Projects",
      "link": "/projects"
    },
    {
      "text": "About",
      "items": [
        {
          "text": "Team",
          "link": "/about/team"
        },
        {
          "text": "blog",
          "link": "/blog/"
        }
      ]
    }
  ],
  "sidebar": {
    "/docs/examples/vitepress": [
      {
        "text": "Examples",
        "items": [
          {
            "text": "Markdown Examples",
            "link": "/docs/examples/vitepress/markdown-examples"
          },
          {
            "text": "Runtime API Examples",
            "link": "/docs/examples/vitepress/api-examples"
          },
          {
            "text": "Emoji",
            "link": "/docs/examples/vitepress/emoji"
          }
        ]
      }
    ],
    "/docs/openai": [
      {
        "text": "GET STARTED",
        "base": "/docs/openai",
        "items": [
          {
            "text": "Quickstart",
            "link": "/quickstart"
          },
          {
            "text": "Quickstart(chat)",
            "link": "/quickstart-chat"
          },
          {
            "text": "Libraries",
            "link": "/libraries"
          }
        ]
      },
      {
        "text": "CORE CONCEPTS",
        "base": "/docs/openai",
        "items": [
          {
            "text": "Text and prompting",
            "link": "/guides/text"
          },
          {
            "text": "Text and prompting(chat)",
            "link": "/guides/text-chat"
          },
          {
            "text": "Images and vision",
            "link": "/guides/images-vision"
          },
          {
            "text": "Images and vision(chat)",
            "link": "/guides/images-vision-chat"
          },
          {
            "text": "Audio and speech",
            "link": "/guides/audio"
          },
          {
            "text": "Structured Outputs",
            "link": "/guides/structured-outputs"
          },
          {
            "text": "Structured Outputs(chat)",
            "link": "/guides/structured-outputs-chat"
          },
          {
            "text": "Function calling",
            "link": "/guides/function-calling"
          },
          {
            "text": "Function calling(chat)",
            "link": "/guides/function-calling-chat"
          },
          {
            "text": "Conversation state",
            "link": "/guides/conversation-state"
          },
          {
            "text": "Conversation state(chat)",
            "link": "/guides/conversation-state-chat"
          },
          {
            "text": "Streaming",
            "link": "/guides/streaming-responses"
          },
          {
            "text": "Streaming(chat)",
            "link": "/guides/streaming-responses-chat"
          },
          {
            "text": "File inputs",
            "link": "/guides/pdf-files"
          },
          {
            "text": "File inputs(chat)",
            "link": "/guides/pdf-files-chat"
          },
          {
            "text": "Reasoning",
            "link": "/guides/reasoning"
          },
          {
            "text": "Reasoning(chat)",
            "link": "/guides/reasoning-chat"
          }
        ]
      },
      {
        "text": "BUILT-IN TOOLS",
        "base": "/docs/openai",
        "items": [
          {
            "text": "Using built-in tools",
            "link": "/guides/tools"
          },
          {
            "text": "Web search",
            "link": "/guides/tools-web-search"
          },
          {
            "text": "File search",
            "link": "/guides/tools-file-search"
          },
          {
            "text": "Computer use",
            "link": "/guides/tools-computer-use"
          }
        ]
      },
      {
        "text": "AGENTS",
        "items": [
          {
            "text": "Building agents",
            "link": "/docs/openai/guides/agents"
          },
          {
            "text": "Voice agents",
            "link": "/docs/openai/guides/voice-agents"
          },
          {
            "text": "Voice agents(chained)",
            "link": "/docs/openai/guides/voice-agents-chained"
          },
          {
            "text": "Agents SDK",
            "link": "https://openai.github.io/openai-agents-python/"
          }
        ]
      },
      {
        "text": "REALTIME API",
        "base": "/docs/openai",
        "items": [
          {
            "text": "Using the Realtime API",
            "link": "/guides/realtime"
          },
          {
            "text": "Realtime conversations",
            "link": "/guides/realtime-conversations"
          },
          {
            "text": "Realtime transcription",
            "link": "/guides/realtime-transcription"
          },
          {
            "text": "Voice activity detection",
            "link": "/guides/realtime-vad"
          }
        ]
      },
      {
        "text": "MODEL OPTIMIZATION",
        "base": "/docs/openai",
        "items": [
          {
            "text": "Overview",
            "link": "/guides/model-optimization"
          },
          {
            "text": "Evals",
            "link": "/guides/evals"
          },
          {
            "text": "Fine-tuning",
            "link": "/guides/fine-tuning"
          },
          {
            "text": "Supervised fine-tuning",
            "link": "/guides/supervised-fine-tuning"
          },
          {
            "text": "Vision fine-tuning",
            "link": "/guides/vision-fine-tuning"
          },
          {
            "text": "Direct preference optimization",
            "link": "/guides/direct-preference-optimization"
          },
          {
            "text": "Reinforcement fine-tuning",
            "link": "/guides/reinforcement-fine-tuning"
          },
          {
            "text": "Graders",
            "link": "/guides/graders"
          },
          {
            "text": "Distillation",
            "link": "/guides/distillation"
          }
        ]
      },
      {
        "text": "SPECIALIZED MODELS",
        "base": "/docs/openai",
        "items": [
          {
            "text": "Image generation",
            "link": "/guides/image-generation"
          },
          {
            "text": "Text to speech",
            "link": "/guides/text-to-speech"
          },
          {
            "text": "Speech to text",
            "link": "/guides/speech-to-text"
          },
          {
            "text": "Embeddings",
            "link": "/guides/embeddings"
          },
          {
            "text": "Moderation",
            "link": "/guides/moderation"
          }
        ]
      },
      {
        "text": "OPENAI PLATFORM",
        "base": "/docs/openai",
        "items": [
          {
            "text": "Retrieval",
            "link": "/guides/retrieval"
          },
          {
            "text": "Batch",
            "link": "/guides/batch"
          },
          {
            "text": "Prompt generation",
            "link": "/guides/prompt-generation"
          }
        ]
      },
      {
        "text": "CODEX",
        "items": [
          {
            "text": "Codex",
            "link": "/docs/openai/guides/codex"
          },
          {
            "text": "Local shell tool",
            "link": "/docs/openai/guides/tools-local-shell"
          },
          {
            "text": "Codex CLI",
            "link": "https://github.com/openai/codex"
          }
        ]
      },
      {
        "text": "BEST PRACTICES",
        "base": "/docs/openai",
        "items": [
          {
            "text": "Production best practices",
            "link": "/guides/production-best-practices"
          },
          {
            "text": "Safety best practices",
            "link": "/guides/safety-best-practices"
          },
          {
            "text": "Prompt Caching",
            "link": "/guides/prompt-caching"
          },
          {
            "text": "Predicted Outputs",
            "link": "/guides/predicted-outputs"
          },
          {
            "text": "Reasoning best practices",
            "link": "/guides/reasoning-best-practices"
          },
          {
            "text": "Evals design",
            "link": "/guides/evals-design"
          },
          {
            "text": "Fine-tuning best practices",
            "link": "/guides/fine-tuning-best-practices"
          },
          {
            "text": "Reinforcement fine-tuning use cases",
            "link": "/guides/rft-use-cases"
          },
          {
            "text": "Model selection",
            "link": "/guides/model-selection"
          },
          {
            "text": "Latency optimization",
            "link": "/guides/latency-optimization"
          },
          {
            "text": "Accuracy optimization",
            "link": "/guides/accuracy-optimization"
          },
          {
            "text": "Advanced usage",
            "link": "/guides/advanced-usage"
          },
          {
            "text": "Responses vs. Chat Completions",
            "link": "/guides/responses-vs-chat-completions"
          },
          {
            "text": "Flex processing",
            "link": "/guides/flex-processing"
          }
        ]
      },
      {
        "text": "ASSISTANTS API",
        "base": "/docs/openai",
        "items": [
          {
            "text": "Overview",
            "link": "/assistants/overview"
          },
          {
            "text": "Quickstart",
            "link": "/assistants/quickstart"
          },
          {
            "text": "Deep dive",
            "link": "/assistants/deep-dive"
          },
          {
            "text": "Tools",
            "collapsed": true,
            "items": [
              {
                "text": "File Search",
                "link": "/assistants/tools/file-search"
              },
              {
                "text": "Code interpreter",
                "link": "/assistants/tools/code-interpreter"
              },
              {
                "text": "Function calling",
                "link": "/assistants/tools/function-calling"
              }
            ]
          },
          {
            "text": "What's new",
            "link": "/assistants/whats-new"
          }
        ]
      },
      {
        "text": "RESOURCES",
        "items": [
          {
            "text": "Terms and policies",
            "link": "https://openai.com/policies/"
          },
          {
            "text": "Changelog",
            "link": "https://platform.openai.com/docs/changelog"
          },
          {
            "text": "Your data",
            "link": "/docs/openai/guides/your-data"
          },
          {
            "text": "Rate limits",
            "link": "/docs/openai/guides/rate-limits"
          },
          {
            "text": "Deprecations",
            "link": "/docs/openai/deprecations"
          },
          {
            "text": "ChatGPT Actions",
            "base": "/docs/openai",
            "collapsed": true,
            "items": [
              {
                "text": "Introduction",
                "link": "/actions/introduction"
              },
              {
                "text": "Getting started",
                "link": "/actions/getting-started"
              },
              {
                "text": "Actions library",
                "link": "/actions/actions-library"
              },
              {
                "text": "Authentication",
                "link": "/actions/authentication"
              },
              {
                "text": "Production",
                "link": "/actions/production"
              },
              {
                "text": "Data retrieval",
                "link": "/actions/data-retrieval"
              },
              {
                "text": "Sending files",
                "link": "/actions/sending-files"
              }
            ]
          }
        ]
      },
      {
        "text": "",
        "items": [
          {
            "text": "Cookbook",
            "link": "https://cookbook.openai.com/"
          },
          {
            "text": "Forum",
            "link": "https://community.openai.com/categories"
          },
          {
            "text": "Help",
            "link": ""
          }
        ]
      }
    ]
  },
  "footer": {
    "message": "build with <a href=\"https://github.com/vuejs/vitepress\">vitepress</a>",
    "copyright": "Copyright © 2023-present by NOTHING"
  },
  "socialLinks": [
    {
      "icon": "wechat",
      "link": "/about/team"
    }
  ]
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "docs/examples/vitepress/api-examples.md",
  "filePath": "docs/examples/vitepress/api-examples.md",
  "lastUpdated": 1747747486000
}

Page Frontmatter

{
  "outline": "deep"
}

More

Check out the documentation for the full list of runtime APIs.

build with vitepress