DEV Community

崔棉大师
崔棉大师

Posted on • Originally published at github.com

How to use Kimi K3 with an OpenAI-compatible API endpoint

Kimi K3 is attracting attention from developers who want a strong Chinese LLM for coding, long-context work, agents, document processing, and general API workflows.

One practical question comes up quickly:

Can I use Kimi K3 through the same OpenAI-compatible API format that my existing tools already support?

Yes. This guide shows one working path using lizh.ai as an independent OpenAI-compatible API gateway.

Important note: lizh.ai is not the official Moonshot AI or Kimi website. It is an independent API gateway that lets you call models through a familiar /v1/chat/completions interface. For official model behavior and provider-specific details, always check the Kimi documentation as well.

What you will configure

You only need three values:

Base URL: https://lizh.ai/v1
Model ID: kimi-k3
API Key: your lizh.ai API key
Enter fullscreen mode Exit fullscreen mode

You can create an API key at:

https://lizh.ai/keys

You can check the current model list and pricing at:

https://lizh.ai/pricing

1. Set your API key

On macOS or Linux:

export LIZH_API_KEY="your_lizh_api_key"
Enter fullscreen mode Exit fullscreen mode

For production usage, store this in your server secret manager, CI/CD secret store, or environment variable system. Do not hard-code it in source code.

2. Test Kimi K3 with cURL

Start with a small request:

curl https://lizh.ai/v1/chat/completions \
  -H "Authorization: Bearer ${LIZH_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k3",
    "messages": [
      {
        "role": "user",
        "content": "Write a short test plan for evaluating a long-context coding model."
      }
    ],
    "max_tokens": 500
  }'
Enter fullscreen mode Exit fullscreen mode

This is useful because it removes SDK configuration from the debugging path. If cURL works, your key, model name, and endpoint are basically correct.

3. Use Kimi K3 from Python

Install the OpenAI SDK:

pip install openai
Enter fullscreen mode Exit fullscreen mode

Then call the OpenAI-compatible endpoint:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["LIZH_API_KEY"],
    base_url="https://lizh.ai/v1",
)

response = client.chat.completions.create(
    model="kimi-k3",
    messages=[
        {
            "role": "system",
            "content": "You are a concise technical assistant.",
        },
        {
            "role": "user",
            "content": "Explain when Kimi K3 is useful for long-context coding tasks.",
        },
    ],
    max_tokens=500,
)

print(response.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

Common checks:

  • If you see an authentication error, check that LIZH_API_KEY is set in the same shell where you run Python.
  • If you see a model error, confirm the model name on the pricing/model page.
  • If the response is too long or too expensive for a test, lower max_tokens.

4. Use Kimi K3 from Node.js

Install the SDK:

npm install openai
Enter fullscreen mode Exit fullscreen mode

Create a test script:

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.LIZH_API_KEY,
  baseURL: "https://lizh.ai/v1",
});

const response = await client.chat.completions.create({
  model: "kimi-k3",
  messages: [
    {
      role: "system",
      content: "You are a concise technical assistant.",
    },
    {
      role: "user",
      content: "Give a short checklist for testing an OpenAI-compatible model gateway.",
    },
  ],
  max_tokens: 500,
});

console.log(response.choices[0].message.content);
Enter fullscreen mode Exit fullscreen mode

This works well for quick backend tests, small agent prototypes, and API compatibility checks.

5. Configure Cursor

If your tool supports custom OpenAI-compatible providers, use:

Provider: OpenAI-compatible
Base URL: https://lizh.ai/v1
API Key: your lizh.ai API key
Model: kimi-k3
Enter fullscreen mode Exit fullscreen mode

Then run a small prompt first, for example:

Read this file and explain the main logic in 5 bullets.
Enter fullscreen mode Exit fullscreen mode

After the first successful request, try a real coding workflow:

  • explain a large file,
  • refactor a small function,
  • generate tests,
  • compare two implementations,
  • summarize an error log.

6. Configure Hermes or OpenClaw

For tools that accept YAML-style provider settings, the important values are usually:

base_url: https://lizh.ai/v1
api_key: ${LIZH_API_KEY}
model: kimi-k3
Enter fullscreen mode Exit fullscreen mode

If the tool has a separate provider type, choose an OpenAI-compatible provider rather than an official OpenAI-only provider.

7. Cost and safety checklist

Before using long-context prompts:

  • Start with a short prompt.
  • Set a small max_tokens value.
  • Check the current price before large tests.
  • Review your usage logs after the first request.
  • Keep input, output, and cache-hit costs separate when estimating cost.

This matters because long-context coding and document prompts can become large quickly.

Complete working examples

I put the working cURL, Python, Node.js, Hermes, and OpenClaw examples in this GitHub repo:

https://github.com/Fankouzu/kimi-k3-openai-compatible-examples

You can also read the same examples as a public documentation site:

https://fankouzu.github.io/kimi-k3-openai-compatible-examples/

Related practical guides:

Final thought

The fastest way to evaluate a new model is not to rebuild your whole stack. Start with one OpenAI-compatible request, verify the model name and pricing, then move the same configuration into your coding tool or agent framework.

For Kimi K3 through lizh.ai, the core configuration is:

Base URL: https://lizh.ai/v1
Model ID: kimi-k3
API Key: created at https://lizh.ai/keys
Enter fullscreen mode Exit fullscreen mode

Top comments (0)