---
title: xAI
---

[xAI](https://console.x.ai)는 Grok 모델과 상호작용할 수 있는 API를 제공합니다.

이 예제는 LangChain을 사용하여 xAI 모델과 상호작용하는 방법을 다룹니다.

## 설치

```python
pip install -U langchain-xai

환경 설정

xAI를 사용하려면 API 키를 생성해야 합니다. API 키는 초기화 매개변수 xai_api_key로 전달하거나 환경 변수 XAI_API_KEY로 설정할 수 있습니다.

예제

자세한 내용과 지원되는 기능은 ChatXAI 문서를 참조하세요.
# Querying chat models with xAI

from langchain_xai import ChatXAI

chat = ChatXAI(
    # xai_api_key="YOUR_API_KEY",
    model="grok-4",
)

# stream the response back from the model
for m in chat.stream("Tell me fun things to do in NYC"):
    print(m.content, end="", flush=True)

# if you don't want to do streaming, you can use the invoke method
# chat.invoke("Tell me fun things to do in NYC")

---

<Callout icon="pen-to-square" iconType="regular">
    [Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/providers/xai.mdx)
</Callout>
<Tip icon="terminal" iconType="regular">
    [Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for    real-time answers.
</Tip>
I