Skip to main content

Overview

Moonshot AI provides an OpenAI-compatible API at https://api.moonshot.ai/v1 for Kimi models. The API supports reasoning content via reasoning_content and JSON object output; tool_choice=required is not supported. Model Class: MoonshotAIModel

Authentication

export MOONSHOTAI_API_KEY="..."

Examples

from upsonic import Agent, Task
from upsonic.models.moonshotai import MoonshotAIModel

model = MoonshotAIModel(model_name="kimi-k2-0711-preview")
agent = Agent(model=model)

task = Task("Hello, how are you?")
result = agent.do(task)
print(result)

Model Settings

You can set model parameters in two ways: on the model or on the Agent. On the model:
from upsonic import Agent, Task
from upsonic.models.moonshotai import MoonshotAIModel, MoonshotAIModelSettings

model = MoonshotAIModel(
    model_name="kimi-k2-0711-preview",
    settings=MoonshotAIModelSettings(max_tokens=1024, temperature=0.7)
)
agent = Agent(model=model)
On the Agent:
from upsonic import Agent, Task
from upsonic.models.moonshotai import MoonshotAIModelSettings

agent = Agent(
    model="moonshotai/kimi-k2-0711-preview",
    settings=MoonshotAIModelSettings(max_tokens=1024, temperature=0.7)
)

Parameters

ParameterTypeDescriptionDefaultSource
max_tokensintMaximum tokens to generateModel defaultBase
temperaturefloatSampling temperature (0.0-2.0)1.0Base
top_pfloatNucleus sampling1.0Base
seedintRandom seedNoneBase
stop_sequenceslist[str]Stop sequencesNoneBase
presence_penaltyfloatToken presence penalty0.0Base
frequency_penaltyfloatToken frequency penalty0.0Base
parallel_tool_callsboolAllow parallel toolsTrueBase
timeoutfloatRequest timeout (seconds)600Base