Skip to main content

Documentation Index

Fetch the complete documentation index at: https://sunpeak.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

sunpeak API

Overview

Returns a function to request LLM completions from the host via MCP sampling/createMessage. The host decides which model to use and may modify or reject the request. Check getHostCapabilities()?.sampling before calling. For tool-augmented completions, check ?.sampling?.tools.

Import

import { useCreateSamplingMessage } from 'sunpeak';

Signature

function useCreateSamplingMessage(): (
  params: CreateSamplingMessageParams
) => Promise<CreateMessageResult | CreateMessageResultWithTools | undefined>

CreateSamplingMessageParams

Standard MCP CreateMessageRequest params:
messages
SamplingMessage[]
required
Conversation messages to send to the model.
maxTokens
number
required
Maximum tokens in the response.
systemPrompt
string
System prompt for the model.
temperature
number
Sampling temperature.
tools
Tool[]
Tools the model can call. When provided, the result may include tool_use blocks.

Returns

createSamplingMessage
(params) => Promise<CreateMessageResult | CreateMessageResultWithTools | undefined>
Function to request an LLM completion.

CreateMessageResult

model
string
Model used by the host.
role
string
Response role (typically "assistant").
content
Content
Response content block.
stopReason
string
Why the model stopped ("endTurn", "toolUse", etc.).

Usage

import { useCreateSamplingMessage, useHostInfo } from 'sunpeak';

function SummaryButton({ text }: { text: string }) {
  const createSamplingMessage = useCreateSamplingMessage();
  const { hostCapabilities } = useHostInfo();

  if (!hostCapabilities?.sampling) return null;

  const handleSummarize = async () => {
    const result = await createSamplingMessage({
      messages: [
        { role: "user", content: { type: "text", text: `Summarize: ${text}` } },
      ],
      maxTokens: 200,
    });
    if (result) {
      console.log("Summary:", result.content);
    }
  };

  return <button onClick={handleSummarize}>Summarize</button>;
}