moonshotai/kimi-k2.6
This snippet shows how to call NVIDIA’s integrate API to run the moonshotai/kimi-k2.6 chat model. It covers setting headers, payload fields (model, tokens, temperature) and handling both JSON and stream responses.
- Sample code calls NVIDIA's integrate API (https://integrate.api.nvidia.com/v1/chat/completions) to run moonshotai/kimi-k2.6, requiring only an NVIDIA_API_KEY swapped into the Authorization header.
- Default payload uses temperature 1, top_p 1, a 16,384 token cap, and a fixed seed of 0 for reproducible outputs.
- Same code handles both streaming (line-by-line printing) and non-streaming (full JSON dump) responses by toggling the stream flag and Accept header.
- Snippet is portable and meant to be adapted to any endpoint provider, not just NVIDIA's hosted API.
You start by defining the chat-completion endpoint at https://integrate.api.nvidia.com/v1/chat/completions and building a Python request around it. The headers include an Authorization bearer token pulled from your NVIDIA API key and set the Accept type based on whether you want streaming output or the full JSON response.
Next, you construct a payload dictionary with a single empty “user” message, specify the model as moonshotai/kimi-k2.6, and configure sampling via temperature 1 and top_p 1. You also set a hard cap of 16,384 tokens and lock the seed at 0 to ensure reproducible outputs.
When you send the POST, the code either prints each line as it arrives—if stream is true—or dumps the complete JSON at once when streaming is off. That gives you flexible handling for both real-time and batch use cases.
Finally, the note at the end simply tells you to take this snippet and deploy it on whatever endpoint provider you prefer. You’ll need to supply your own NVIDIA_API_KEY and ensure your environment allows outbound requests to NVIDIA’s integrate API.