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

# Send Requests to GLM-5.2

> Send your first request to GLM-5.2 with the OpenAI-compatible Chat Completions API using Python, JavaScript, or cURL.

export const openingParagraph_0 = "To send a request, complete the following steps:"

export const hideReplaceModelParagraph_0 = true

export const modelId_0 = "zai-org/GLM-5.2"

export const closingParagraph_0 = "Continue to the next page to learn about the model's reasoning parameters."

Use the OpenAI-compatible Chat Completions API to connect to GLM-5.2. You can use the OpenAI Python or JavaScript SDK, or send requests directly with cURL.

If you need a new API key, [create one](/docs/examples/models/overview#create-an-api-key).

## Send a Request

{
openingParagraph_0 ??
"Once you create your FriendliAI API key, you're ready to send your first request:"
}

<Steps>
  <Step title="Set Up Your API Key">
    In your terminal, run the following command:

    ```bash theme={null}
    export FRIENDLIAI_API_KEY="<FRIENDLIAI_API_KEY>"
    ```

    Replace `<FRIENDLIAI_API_KEY>` with your API key.
  </Step>

  <Step title="Install the OpenAI SDK">
    In your terminal, run the following command:

    <CodeGroup>
      ```bash OpenAI Python SDK theme={null}
      pip install openai
      ```

      ```bash OpenAI JavaScript SDK theme={null}
      npm install openai
      ```
    </CodeGroup>
  </Step>

  <Step title="Send Your Request to FriendliAI">
    Run the following code:

    <CodeGroup>
      ```python OpenAI Python SDK wrap theme={null}
      import os
      from openai import OpenAI

      client = OpenAI(
        base_url="https://api.friendli.ai/serverless/v1",
        api_key=os.environ["FRIENDLIAI_API_KEY"],
      )

      completion = client.chat.completions.create(
        model="zai-org/GLM-5.2",
        messages=[
          {"role": "system", "content": "You are a friendly assistant."},
          {"role": "user", "content": "Describe FriendliAI in one sentence."},
        ],
      )

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

      ```javascript OpenAI JavaScript SDK wrap theme={null}
      import OpenAI from "openai"

      const client = new OpenAI({
        baseURL: "https://api.friendli.ai/serverless/v1",
        apiKey: process.env.FRIENDLIAI_API_KEY,
      })

      const completion = await client.chat.completions.create({
        model: "zai-org/GLM-5.2",
        messages: [
          { role: "system", content: "You are a friendly assistant." },
          { role: "user", content: "Describe FriendliAI in one sentence." },
        ],
      })

      console.log(completion.choices[0].message)
      ```

      ```bash cURL wrap theme={null}
      curl -X POST https://api.friendli.ai/serverless/v1/chat/completions \
        -H 'Content-Type: application/json' \
        -H "Authorization: Bearer $FRIENDLIAI_API_KEY" \
        -d '{
          "model": "zai-org/GLM-5.2",
          "messages": [
            {"role": "system", "content": "You are a friendly assistant."},
            {"role": "user", "content": "Describe FriendliAI in one sentence."}
          ]
      }'
      ```
    </CodeGroup>

    {!hideReplaceModelParagraph_0 && (
            <p>
              If you'd like to use a different model, replace <code>{modelId_0}</code> with another model. To browse all models, see <a href="https://friendli.ai/models?products=SERVERLESS">Models &gt; Model APIs</a>.
            </p>
          )}

    <Check>
      FriendliAI returns a response, similar to the following:

      ```json expandable wrap theme={null}
      {
        "id": "chatcmpl-04eb40ba7fc14cf8a51b7869d9cfa76f",
        "object": "chat.completion",
        "choices": [
          {
            "index": 0,
            "message": {
              "role": "assistant",
              "content": "FriendliAI is a generative AI infrastructure company that provides optimized solutions to help businesses deploy large language models faster, more efficiently, and at a lower cost.",
              "reasoning": "...",
              "reasoning_content": "..."
            },
            "logprobs": null,
            "finish_reason": "stop"
          }
        ],
        "created": 1781892285,
        "usage": {
          "completion_tokens": 412,
          "prompt_tokens": 27,
          "prompt_tokens_details": {
            "cached_tokens": 0
          },
          "total_tokens": 439
        },
        "model": "zai-org/GLM-5.2"
      }
      ```
    </Check>
  </Step>
</Steps>

{
closingParagraph_0 ??
"Congratulations. You sent your first request and are ready to build your next project."
}
