Skip to main content

Single-turn Chat

Interact with the Chat Completions API using the OpenAI SDK and cURL:
Before running the examples, set the API Key you created on the platform as the MOONSHOT_API_KEY environment variable.

Multi-turn Chat

Use the model’s output as part of the input to achieve multi-turn conversation:
As the conversation progresses, the number of tokens the model needs to process increases linearly. When necessary, employ optimization strategies such as retaining only the most recent few rounds.

Streaming

Use stream: true to enable streaming responses for a better user experience: