응답에서 텍스트는 completion.choices[0].message.content. completion.message 라고 적으면 안 돼 — choices 는 길이 1 이라도 list. Library 코드에선 n>1 가능성 고려해서 iterate.
usage = billing audit log
매 request 마다 usage.prompt_tokens, completion_tokens, total_tokens 를 request id 와 함께 persist. 두 달 후 bill 이 surprise 일 때 'why' 를 알려주는 게 정확히 이거.
tool_calls 는 null 가능
completion.choices[0].message.tool_calls 는 tool 안 부른 turn 에선 None. Defensive access — getattr(msg, 'tool_calls', None) or [] 같은 패턴이 안전.
Skeleton helper 만들어두면 좋아
Response 마다 {text, finish_reason, prompt_tokens, completion_tokens, tool_calls?} 로 unwrap 하는 헬퍼 1 개 — null-safe, 모든 코드에서 같은 모양으로 사용. Bonus: log line 만들기도 쉬워짐.