LlamaIndex

Use Morse's private, OpenAI-compatible API as the LLM in LlamaIndex for chat, agents, and queries: set it up and check it works.

Give LlamaIndex's OpenAILike Morse's base URL, your key, a model id, and that model's context window.

Terminal
pip install llama-index-llms-openai-like
Python
import os
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="moonshotai/kimi-k3.1-pro",
    api_base="https://inference.trymorse.ai/v1",
    api_key=os.environ["MORSE_API_KEY"],
    is_chat_model=True,
    is_function_calling_model=True,
    context_window=1048576,
)
print(llm.complete("Hello").text)
  • is_chat_model=True sends /v1/chat/completions. Without it, LlamaIndex calls the legacy completions endpoint, which Morse doesn't serve.
  • is_function_calling_model=True lets agents send tools.
  • context_window is the model's context, from the models page.

Streaming

Python
from llama_index.core.llms import ChatMessage

messages = [ChatMessage(role="user", content="Write a haiku about rain.")]
for chunk in llm.stream_chat(messages):
    print(chunk.delta, end="", flush=True)

Agents

A FunctionAgent sends its tools with each request and runs the calls the model returns.

Python
import asyncio
from llama_index.core.agent.workflow import FunctionAgent

def get_weather(city: str) -> str:
    """The weather now in a city."""
    return f"It's raining in {city}."

agent = FunctionAgent(tools=[get_weather], llm=llm)

async def main():
    print(await agent.run("Is it raining in Lisbon?"))

asyncio.run(main())

Send Morse's own parameters

Put them in extra_body inside additional_kwargs.

Python
llm = OpenAILike(
    model="z-ai/glm-5.3",
    api_base="https://inference.trymorse.ai/v1",
    api_key=os.environ["MORSE_API_KEY"],
    is_chat_model=True,
    is_function_calling_model=True,
    context_window=1048576,
    additional_kwargs={"extra_body": {"provider": {"min_privacy": "tee"}}},
)

Morse serves no embeddings. For an index, set Settings.embed_model to an embedding model from elsewhere. See API reference.