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

# LLM

> LLM 클래스는 LLM API 호출 한 건을 chat span으로 기록합니다.

```python theme={"system"}
class LLM(BaseModel): ...
```

LLM API 호출 한 건을 나타냅니다. chat OTel span에 매핑됩니다.

`LLM`은 Pydantic 모델입니다. 인스턴스를 생성할 때 아래 필드를 키워드 인수로 지정할 수 있습니다.

`LLM`은 컨텍스트 관리자이므로 `with` 문에서 사용할 수 있습니다.

<h2 id="fields">
  필드
</h2>

| 필드 | 유형 | 기본값 |
| - | - | - |
| `model` | `str` | `''` |
| `provider_name` | `str` | `''` |
| `response_id` | `str` | `''` |
| `response_model` | `str` | `''` |
| `output_type` | `str` | `''` |
| `system_instructions` | `list[str]` | `[]` |
| `usage` | `Usage` | `Usage()` |
| `reasoning` | `Reasoning` | `Reasoning()` |
| `finish_reasons` | `list[str]` | `[]` |
| `input_messages` | `list[Message]` | `[]` |
| `output_messages` | `list[Message]` | `[]` |
| `media_attachments` | `list[MediaAttachment]` | `[]` |
| `request_temperature` | `Union[float, None]` | `None` |
| `request_max_tokens` | `Union[int, None]` | `None` |
| `request_top_p` | `Union[float, None]` | `None` |
| `request_top_k` | `Union[float, None]` | `None` |
| `request_frequency_penalty` | `Union[float, None]` | `None` |
| `request_presence_penalty` | `Union[float, None]` | `None` |
| `request_seed` | `Union[int, None]` | `None` |
| `request_stop_sequences` | `list[str]` | `[]` |
| `request_choice_count` | `Union[int, None]` | `None` |
| `started_at` | `Union[datetime, None]` | `None` |
| `ended_at` | `Union[datetime, None]` | `None` |

<h2 id="methods">
  메서드
</h2>

<h3 id="output">
  output
</h3>

```python theme={"system"}
def output(content: str) -> LLM: ...
```

output\_messages에 assistant 메시지를 추가합니다.

<h3 id="think">
  think
</h3>

```python theme={"system"}
def think(content: str) -> LLM: ...
```

추론/chain-of-thought 콘텐츠를 설정합니다.

<h3 id="attach_media">
  attach\_media
</h3>

```python theme={"system"}
def attach_media(
    *,
    content: Union[bytes, str] = '',
    uri: str = '',
    file_id: str = '',
    mime_type: str = '',
    modality: str = '',
) -> LLM: ...
```

이 LLM Call에 미디어를 첨부합니다.

소스는 정확히 하나만 지정해야 합니다. 바이트는 base64로 인코딩되어 인라인
GenAI 블롭으로 전송됩니다. 문자열 콘텐츠는 미리 base64로 인코딩되어 있어야 합니다. URI와
공급자 파일 ID는 각각 GenAI URI 파트와 파일 파트로 전송됩니다.

<h3 id="attach_media_url">
  attach\_media\_url
</h3>

```python theme={"system"}
def attach_media_url(url: str, *, modality: str = '') -> LLM: ...
```

이 LLM Call에 data URL 또는 일반 미디어 URI를 첨부합니다.

<h3 id="record">
  record
</h3>

```python theme={"system"}
def record(
    *,
    input_messages: Union[list[Message], None] = None,
    output_messages: Union[list[Message], None] = None,
    media_attachments: Union[list[MediaAttachment], None] = None,
    usage: Union[Usage, None] = None,
    reasoning: Union[Reasoning, str, None] = None,
    response_id: Union[str, None] = None,
    response_model: Union[str, None] = None,
    finish_reasons: Union[list[str], None] = None,
    output_type: Union[str, None] = None,
) -> LLM: ...
```

여러 LLM Call 필드를 한 번의 호출로 설정합니다.

수동으로 계측된 에이전트는 보통 LLM Call이 끝날 때
여덟 개 이상의 필드(`input_messages`, `output_messages`, `usage`,
`response_id` 등)를 하나씩 할당하여 chat span을 구성합니다. `record(...)`를 사용하면 이러한 할당을
단일 키워드 호출로 합칠 수 있어 기록 코드를 간결하게 유지할 수 있습니다.

명시적으로 전달된(`None`이 아닌) 필드만 적용되며,
기존 값은 그대로 유지됩니다. `reasoning`에는
`Reasoning` 인스턴스 또는 일반 문자열(자동으로 래핑됨)을 전달할 수 있습니다.
메서드 체이닝을 위해 `self`를 반환합니다.

<h3 id="end">
  end
</h3>

```python theme={"system"}
def end() -> None: ...
```

<h3 id="start">
  start
</h3>

```python theme={"system"}
def start() -> Self: ...
```

이 span을 한 번 시작합니다. 컨텍스트 관리자로 진입할 때도 동일한 경로를 사용합니다.

<h3 id="record_error">
  record\_error
</h3>

```python theme={"system"}
def record_error(error: BaseException) -> Self: ...
```

span을 종료하지 않고 실패를 기록합니다. span을 종료할 준비가 되면 `end()`를 호출하세요.

<h3 id="set_attributes">
  set\_attributes
</h3>

```python theme={"system"}
def set_attributes(attributes: dict[str, Any]) -> Self: ...
```

이 span에 임의의 OTel 속성을 설정합니다.

키가 하나든 여러 개든 dict를 전달하세요. 키가 하나인 경우에는
`span.set_attributes({"weave.tag": "value"})`와 같이 호출합니다. OTel의
`Span.set_attributes`와 동일하게 동작합니다.

`start_*` 팩토리, `start()` 또는 `with`로 span을
시작한 후, span이 종료되기 전에 호출해야 합니다. 이 윈도우 밖에서 호출하면 아무 작업도
수행되지 않고 경고가 로깅됩니다. 일괄 수집 시에는 객체에 선언된 필드를
직접 채운 다음 `log_turn` / `log_conversation`에 전달하세요.
