> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyfast.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Kimi K3

> Call Moonshot AI's Kimi K3 flagship multimodal model through the AnyFast OpenAI-compatible API.

Kimi K3 is Moonshot AI's flagship model for long-horizon coding, end-to-end knowledge work, and deep reasoning. It provides a 1M-token context window, image understanding, and always-on reasoning through AnyFast's OpenAI-compatible Chat Completions API.

<Info>
  The model ID is `kimi-k3`. K3 always reasons and uses the top-level `reasoning_effort` field instead of the K2.x `thinking` object.
</Info>

## Key capabilities

* **1M-token context** — Process large codebases, long documents, and extended agent histories
* **2.8T sparse architecture** — Uses KDA, Attention Residuals, and Stable LatentMoE with 16 of 896 experts active per token
* **Multimodal input** — Understand text and images in one conversation
* **Always-on reasoning** — Configure effort with `low`, `high`, or `max`; the default is `max`
* **Long-horizon coding** — Work across large repositories and coordinate terminal or external tools
* **Structured output** — Constrain final answers with JSON Mode or strict JSON Schema
* **Tool use** — Supports `auto`, `none`, and `required` for `tool_choice`
* **Automatic context caching** — Reuse an unchanged long prefix without creating a cache ID
* **Partial Mode** — Continue generation from a supplied assistant prefix

## Quick example

<CodeGroup>
  ```bash cURL theme={null}
  curl https://www.anyfast.ai/v1/chat/completions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "kimi-k3",
      "messages": [
        {"role": "user", "content": "Explain Kimi K3 in one sentence."}
      ]
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="YOUR_API_KEY",
      base_url="https://www.anyfast.ai/v1"
  )

  completion = client.chat.completions.create(
      model="kimi-k3",
      messages=[
          {"role": "user", "content": "Explain Kimi K3 in one sentence."}
      ]
  )

  print(completion.choices[0].message.content)
  ```
</CodeGroup>

## Thinking effort

K3 always has reasoning enabled. Set the top-level `reasoning_effort` field to `low`, `high`, or `max` according to the task. The default is `max`.

```python theme={null}
completion = client.chat.completions.create(
    model="kimi-k3",
    reasoning_effort="high",
    messages=[
        {"role": "user", "content": "Prove that the square root of 2 is irrational."}
    ]
)

print(completion.choices[0].message.content)
```

<Warning>
  Do not send the K2.x `thinking` parameter. K3 reasoning cannot be disabled. Changing `reasoning_effort` during a conversation also invalidates prefix-cache hits, so choose the level before the conversation starts.
</Warning>

## Streaming

In streaming mode, reasoning is returned through `delta.reasoning`, while the final answer is returned through `delta.content`. A non-streaming response also includes `message.reasoning` and may include `message.reasoning_details`.

```python theme={null}
stream = client.chat.completions.create(
    model="kimi-k3",
    reasoning_effort="max",
    messages=[
        {"role": "user", "content": "Explain why the sky is blue."}
    ],
    stream=True,
    stream_options={"include_usage": True}
)

for chunk in stream:
    if not chunk.choices:
        continue
    delta = chunk.choices[0].delta
    reasoning = getattr(delta, "reasoning", None)
    if reasoning:
        print(reasoning, end="", flush=True)
    if delta.content:
        print(delta.content, end="", flush=True)
```

## Image input

Multimodal `content` must be an array of typed objects. AnyFast accepts an image as a public URL or Base64 Data URI.

```python theme={null}
import base64
from pathlib import Path

image_data = base64.b64encode(Path("image.png").read_bytes()).decode()

completion = client.chat.completions.create(
    model="kimi-k3",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/png;base64,{image_data}"
                    }
                },
                {"type": "text", "text": "Describe this image."}
            ]
        }
    ]
)

print(completion.choices[0].message.content)
```

Official guidance recommends limiting images to 4K.

## Structured output

Use `response_format.type: "json_schema"` with `strict: true` to constrain the final `message.content`.

```python theme={null}
import json

completion = client.chat.completions.create(
    model="kimi-k3",
    messages=[
        {"role": "user", "content": "Lin is 28 years old. Extract the name and age."}
    ],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "person",
            "strict": True,
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "age": {"type": "integer"}
                },
                "required": ["name", "age"],
                "additionalProperties": False
            }
        }
    }
)

person = json.loads(completion.choices[0].message.content)
print(person)
```

Only parse `message.content`; `reasoning` and `reasoning_details` are not part of the structured result.

## Tool calling

K3 supports top-level function tools and accepts `auto`, `none`, and `required` for `tool_choice`.

```python theme={null}
completion = client.chat.completions.create(
    model="kimi-k3",
    messages=[
        {"role": "user", "content": "What is the weather in Shanghai?"}
    ],
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "Get the weather for a city",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "city": {"type": "string"}
                    },
                    "required": ["city"]
                }
            }
        }
    ],
    tool_choice="required"
)

print(completion.choices[0].message.tool_calls)
```

After executing a tool, append the complete assistant message and one `role: "tool"` result for each `tool_call_id`, then call the model again.

## Partial Mode

Append an assistant message with `partial: true` to continue from a prefix.

```python theme={null}
prefix = "Conclusion: "

completion = client.chat.completions.create(
    model="kimi-k3",
    messages=[
        {"role": "user", "content": "Explain why API compatibility matters."},
        {"role": "assistant", "content": prefix, "partial": True}
    ]
)

print(prefix + (completion.choices[0].message.content or ""))
```

## Parameters and limits

| Parameter               | Type           | Required | Description                                                                                                                |
| ----------------------- | -------------- | -------- | -------------------------------------------------------------------------------------------------------------------------- |
| `model`                 | string         | Yes      | Must be `kimi-k3`                                                                                                          |
| `messages`              | array          | Yes      | Conversation history. Supports text, image content, and tool messages                                                      |
| `reasoning_effort`      | string         | No       | `low`, `high`, or `max`. Default: `max`                                                                                    |
| `max_completion_tokens` | integer        | No       | Default: 131,072; maximum: 1,048,576. Input plus output must fit the 1M context window                                     |
| `stream`                | boolean        | No       | Enable SSE streaming. Default: `false`                                                                                     |
| `stream_options`        | object         | No       | Set `include_usage: true` to receive usage in the final stream chunk                                                       |
| `response_format`       | object         | No       | `text`, `json_object`, or `json_schema`                                                                                    |
| `tools`                 | array          | No       | Function definitions available to the model                                                                                |
| `tool_choice`           | string         | No       | `auto`, `none`, or `required`                                                                                              |
| `stop`                  | string / array | No       | Up to 5 stop strings, each no longer than 32 bytes. A stop string can terminate reasoning before final content is produced |
| `prompt_cache_key`      | string         | No       | Stable session or task identifier that can improve cache hit rates                                                         |
| `safety_identifier`     | string         | No       | Stable, preferably hashed identifier for the end user                                                                      |

<Note>
  `temperature` is fixed at `1.0`, `top_p` at `0.95`, `n` at `1`, and both penalties at `0`. Do not send these parameters explicitly. For multi-turn conversations and tool calls, return the complete assistant message unchanged, including `reasoning`, `reasoning_details`, and `tool_calls`.
</Note>

<Note>
  Automatic context caching applies to unchanged prefixes. The previous request prompt must exceed 256 tokens before a later request can hit the prefix cache. Reuse a stable `prompt_cache_key` for the same session or task when possible.
</Note>

<Card title="API Reference" icon="code" href="/api-reference/model-api/moonshot/kimi-k3">
  View the interactive API reference for Kimi K3.
</Card>

<script src="/feedback.js" />
