응답 텍스트는 completion.choices[0].message.content 에 있어. completion.message 로 바로 접근할 수는 없어. choices 는 원소가 하나뿐이어도 배열이고, n>1 을 허용하는 공용 코드라면 모든 원소를 순회해야 해.
usage 는 비용을 설명하는 기록이야
요청마다 usage.prompt_tokens, completion_tokens, total_tokens 를 request ID 와 함께 저장해. 나중에 청구액이 예상과 다를 때 어떤 호출이 비용을 만들었는지 추적할 근거가 돼.
tool_calls 는 없을 수도 있어
도구를 호출하지 않은 turn 에서는 completion.choices[0].message.tool_calls 가 None 일 수 있어. getattr(msg, 'tool_calls', None) or [] 처럼 값이 없을 때 빈 배열로 다루는 방식이 안전해.
공통으로 풀어주는 helper 를 만들어
응답을 {text, finish_reason, prompt_tokens, completion_tokens, tool_calls?} 형태로 바꾸는 null-safe helper 하나를 두면 모든 호출부가 같은 구조를 쓸 수 있어. 로그를 남기기도 훨씬 쉬워져.