원라우터의 사용 회계
AI 모델 토큰 사용 추적
By 앤드류 젱 •
AI 모델 토큰 사용 추적



2025. 12. 21.
앤드류 젱
OneRouter API는 추가 API 호출 없이 AI 모델 사용량을 추적할 수 있는 사용 회계 기능을 제공합니다. 이 기능은 API 응답에 직접 토큰 수, 비용 및 캐싱 상태에 대한 자세한 정보를 제공합니다.
사용이 활성화되면 API는 다음과 같은 자세한 사용 정보를 반환합니다:
모델의 기본 토크나이저를 사용한 프롬프트 및 완성 토큰 수
크레딧으로 표시된 비용
추론 토큰 수 (해당되는 경우)
캐시된 토큰 수 (가능한 경우)
이 정보는 스트리밍 응답의 마지막 SSE 메시지에 포함되거나 비스트리밍 요청의 전체 응답에 포함됩니다.
요청에 usage 매개변수를 포함하여 사용 회계를 활성화할 수 있습니다:
import requests import json response = requests.post( url="https://llm.onerouter.pro/v1/chat/completions", headers={ "Authorization": "Bearer <<API Keys>>", "Content-Type": "application/json" }, data=json.dumps({ "model": "google-ai-studio/gemini-2.5-flash-preview-09-2025", "messages": [ { "role": "user", "content": "What is the meaning of life?" } ], "usage": { "include": True } }) ) print(response.json())
사용 회계가 활성화된 경우 응답에는 자세한 토큰 정보와 cost 항목 및 상세 비용을 포함하는 cost_details 객체가 포함됩니다:
{ 'choices': [{ 'finish_reason': 'stop', 'index': 0, 'logprobs': None, 'message': { 'content': 'This is perhaps the most profound and widely debated question in human history. The truth is, there is no single, universally accepted answer.\n\nThe "meaning of life" is a concept that is approached very differently across disciplines, cultures, and individual beliefs. Here is an overview of the major perspectives:\n\n---\n\n## 1. Philosophical Perspectives\n\nPhilosophy attempts to logically define existence and purpose.\n\n| Perspective | Core Idea | Key Concept |\n| :--- | :--- | :--- |\n| **Nihilism** | Life is inherently without objective meaning, purpose, or intrinsic value. Any purpose is an illusion. | Meaninglessness, Absurdity (often a precursor to Existentialism). |\n| **Absurdism** | The conflict between humanity\'s inherent search for meaning and the universe\'s silent, objective meaninglessness (**The Absurd**). The meaning is found in rebelling against the Absurd by embracing life fully despite its lack of ultimate purpose. | Revolt, Freedom, Passion (Albert Camus). |\n| **Existentialism** | Existence precedes essence. Humans are born a "blank slate" and must create their own meaning through choices, freedom, and responsibility. Meaning is subjective and individually constructed. | Radical Freedom, Responsibility, Subjectivity (Sartre, de Beauvoir). |\n| **Hedonism/Utilitarianism** | The ultimate meaning or good is the maximization of pleasure and the minimization of pain (utility). Life\'s purpose is to seek happiness. | Utility, Pleasure, The Greatest Good for the Greatest Number. |\n| **Stoicism** | Meaning is found in living in accordance with nature and reason. Focus on what you can control (your judgments and reactions) and accept what you cannot. Virtue is the sole good. | Virtue, Resilience, Acceptance. |\n\n---\n\n## 2. Religious and Spiritual Perspectives\n\nReligions generally posit that life has a transcendent, divinely ordained purpose.\n\n* **Christianity/Islam/Judaism:** Meaning is found in serving God, following divine law, achieving salvation, and preparing for an afterlife. The purpose is to fulfill the covenant or will of the Creator.\n* **Buddhism:** The meaning of life is to escape suffering (Dukkha) caused by desire, achieve enlightenment (Nirvana), and break the cycle of reincarnation (Samsara). This is often achieved through compassion and ethical conduct.\n* **Hinduism:** Meaning is tied to *Dharma* (righteous conduct/duty) and *Moksha* (liberation/union with the ultimate reality, Brahman). The goal is to fulfill one’s duty within the cosmic order.\n* **Spirituality (Non-denominational):** Meaning is often found in connection—to nature, to other beings, or to a higher power—and in personal growth or evolution.\n\n---\n\n## 3. Scientific and Biological Perspectives\n\nScience approaches the question from an empirical viewpoint, focusing on observable functions.\n\n* **Biological Imperative:** From an evolutionary standpoint, the meaning of life is the perpetuation of the species. The goal of any organism is to survive long enough to reproduce and pass on its genetic material.\n* **Cognitive Science:** The function of human life is the processing of information, learning, adaptation, and the creation of culture, knowledge, and complex systems. Meaning can be seen as the ultimate emergent property of a highly complex brain interacting with the environment.\n* **Cosmic Perspective (Atheistic/Naturalistic):** In the vastness of the cosmos, human life has no inherent cosmic significance. Meaning, if it exists, is purely self-imposed and human-centered.\n\n---\n\n## 4. Psychological Perspectives\n\nPsychology focuses on the internal experience of purpose, fulfillment, and well-being.\n\n* **Logotherapy (Viktor Frankl):** Meaning is found in the relentless search for purpose, even amidst suffering. Frankl, a Holocaust survivor, argued that meaning can be found in three primary ways:\n 1. Creating a work or doing a deed.\n 2. Experiencing something or loving someone.\n 3. The attitude we take toward unavoidable suffering.\n* **Humanistic Psychology (Maslow/Rogers):** The meaning of life is **Self-Actualization**—the realization of one\'s full potential and inherent capabilities. It is the drive to become the best possible version of oneself.\n* **Positive Psychology (Seligman):** Meaning is a core component of flourishing (**PERMA Model**). It is achieved by belonging to and serving something larger than oneself.\n\n---\n\n## Conclusion: The Answer May Be a Verb\n\nSince there is no objective meaning decreed by the universe, most contemporary thought (philosophical and psychological) suggests that **meaning is not something to be discovered, but something to be created.**\n\nIf you accept that the universe is indifferent, the meaning of life becomes:\n\n### 1. The Meaning You Choose to Create\n\nIt is the subjective purpose you assign to your own existence. This could be love, art, justice, connection, knowledge, or helping others.\n\n### 2. The Experience of Living\n\nThe ultimate meaning might simply be the experience itself—the engagement with the world, the appreciation of beauty, the capacity for connection, and the pursuit of growth.\n\nIn essence, **The meaning of life is the life you lead.**', 'role': 'assistant' } }], 'cost': 0.002835, 'cost_details': { 'audio_cost': 0, 'cache_prompt_cost': 0, 'cache_write_cost': 0, 'generation_cost': 0, 'image_cost': 0, 'input_prompt_cost': 2.4e-06, 'output_prompt_cost': 0.002832727, 'tools_cost': 0, 'video_cost': 0 }, 'created': 1766026675, 'discounted': '1', 'id': 'chatcmpl-202512180257506444719362giBMqDX', 'model': 'gemini-2.5-flash-preview-09-2025', 'object': 'chat.completion', 'request_id': '8dce2dd0fd4c4bfeb4374df8fb32a8a6', 'usage': { 'completion_tokens': 1133, 'input_tokens': 0, 'output_tokens': 0, 'prompt_tokens': 8, 'prompt_tokens_details': { 'text_tokens': 8 }, 'server_tool_use': { 'web_search_requests': '' }, 'total_tokens': 1141, 'ttft': 0 } }
OneRouter API는 추가 API 호출 없이 AI 모델 사용량을 추적할 수 있는 사용 회계 기능을 제공합니다. 이 기능은 API 응답에 직접 토큰 수, 비용 및 캐싱 상태에 대한 자세한 정보를 제공합니다.
사용이 활성화되면 API는 다음과 같은 자세한 사용 정보를 반환합니다:
모델의 기본 토크나이저를 사용한 프롬프트 및 완성 토큰 수
크레딧으로 표시된 비용
추론 토큰 수 (해당되는 경우)
캐시된 토큰 수 (가능한 경우)
이 정보는 스트리밍 응답의 마지막 SSE 메시지에 포함되거나 비스트리밍 요청의 전체 응답에 포함됩니다.
요청에 usage 매개변수를 포함하여 사용 회계를 활성화할 수 있습니다:
import requests import json response = requests.post( url="https://llm.onerouter.pro/v1/chat/completions", headers={ "Authorization": "Bearer <<API Keys>>", "Content-Type": "application/json" }, data=json.dumps({ "model": "google-ai-studio/gemini-2.5-flash-preview-09-2025", "messages": [ { "role": "user", "content": "What is the meaning of life?" } ], "usage": { "include": True } }) ) print(response.json())
사용 회계가 활성화된 경우 응답에는 자세한 토큰 정보와 cost 항목 및 상세 비용을 포함하는 cost_details 객체가 포함됩니다:
{ 'choices': [{ 'finish_reason': 'stop', 'index': 0, 'logprobs': None, 'message': { 'content': 'This is perhaps the most profound and widely debated question in human history. The truth is, there is no single, universally accepted answer.\n\nThe "meaning of life" is a concept that is approached very differently across disciplines, cultures, and individual beliefs. Here is an overview of the major perspectives:\n\n---\n\n## 1. Philosophical Perspectives\n\nPhilosophy attempts to logically define existence and purpose.\n\n| Perspective | Core Idea | Key Concept |\n| :--- | :--- | :--- |\n| **Nihilism** | Life is inherently without objective meaning, purpose, or intrinsic value. Any purpose is an illusion. | Meaninglessness, Absurdity (often a precursor to Existentialism). |\n| **Absurdism** | The conflict between humanity\'s inherent search for meaning and the universe\'s silent, objective meaninglessness (**The Absurd**). The meaning is found in rebelling against the Absurd by embracing life fully despite its lack of ultimate purpose. | Revolt, Freedom, Passion (Albert Camus). |\n| **Existentialism** | Existence precedes essence. Humans are born a "blank slate" and must create their own meaning through choices, freedom, and responsibility. Meaning is subjective and individually constructed. | Radical Freedom, Responsibility, Subjectivity (Sartre, de Beauvoir). |\n| **Hedonism/Utilitarianism** | The ultimate meaning or good is the maximization of pleasure and the minimization of pain (utility). Life\'s purpose is to seek happiness. | Utility, Pleasure, The Greatest Good for the Greatest Number. |\n| **Stoicism** | Meaning is found in living in accordance with nature and reason. Focus on what you can control (your judgments and reactions) and accept what you cannot. Virtue is the sole good. | Virtue, Resilience, Acceptance. |\n\n---\n\n## 2. Religious and Spiritual Perspectives\n\nReligions generally posit that life has a transcendent, divinely ordained purpose.\n\n* **Christianity/Islam/Judaism:** Meaning is found in serving God, following divine law, achieving salvation, and preparing for an afterlife. The purpose is to fulfill the covenant or will of the Creator.\n* **Buddhism:** The meaning of life is to escape suffering (Dukkha) caused by desire, achieve enlightenment (Nirvana), and break the cycle of reincarnation (Samsara). This is often achieved through compassion and ethical conduct.\n* **Hinduism:** Meaning is tied to *Dharma* (righteous conduct/duty) and *Moksha* (liberation/union with the ultimate reality, Brahman). The goal is to fulfill one’s duty within the cosmic order.\n* **Spirituality (Non-denominational):** Meaning is often found in connection—to nature, to other beings, or to a higher power—and in personal growth or evolution.\n\n---\n\n## 3. Scientific and Biological Perspectives\n\nScience approaches the question from an empirical viewpoint, focusing on observable functions.\n\n* **Biological Imperative:** From an evolutionary standpoint, the meaning of life is the perpetuation of the species. The goal of any organism is to survive long enough to reproduce and pass on its genetic material.\n* **Cognitive Science:** The function of human life is the processing of information, learning, adaptation, and the creation of culture, knowledge, and complex systems. Meaning can be seen as the ultimate emergent property of a highly complex brain interacting with the environment.\n* **Cosmic Perspective (Atheistic/Naturalistic):** In the vastness of the cosmos, human life has no inherent cosmic significance. Meaning, if it exists, is purely self-imposed and human-centered.\n\n---\n\n## 4. Psychological Perspectives\n\nPsychology focuses on the internal experience of purpose, fulfillment, and well-being.\n\n* **Logotherapy (Viktor Frankl):** Meaning is found in the relentless search for purpose, even amidst suffering. Frankl, a Holocaust survivor, argued that meaning can be found in three primary ways:\n 1. Creating a work or doing a deed.\n 2. Experiencing something or loving someone.\n 3. The attitude we take toward unavoidable suffering.\n* **Humanistic Psychology (Maslow/Rogers):** The meaning of life is **Self-Actualization**—the realization of one\'s full potential and inherent capabilities. It is the drive to become the best possible version of oneself.\n* **Positive Psychology (Seligman):** Meaning is a core component of flourishing (**PERMA Model**). It is achieved by belonging to and serving something larger than oneself.\n\n---\n\n## Conclusion: The Answer May Be a Verb\n\nSince there is no objective meaning decreed by the universe, most contemporary thought (philosophical and psychological) suggests that **meaning is not something to be discovered, but something to be created.**\n\nIf you accept that the universe is indifferent, the meaning of life becomes:\n\n### 1. The Meaning You Choose to Create\n\nIt is the subjective purpose you assign to your own existence. This could be love, art, justice, connection, knowledge, or helping others.\n\n### 2. The Experience of Living\n\nThe ultimate meaning might simply be the experience itself—the engagement with the world, the appreciation of beauty, the capacity for connection, and the pursuit of growth.\n\nIn essence, **The meaning of life is the life you lead.**', 'role': 'assistant' } }], 'cost': 0.002835, 'cost_details': { 'audio_cost': 0, 'cache_prompt_cost': 0, 'cache_write_cost': 0, 'generation_cost': 0, 'image_cost': 0, 'input_prompt_cost': 2.4e-06, 'output_prompt_cost': 0.002832727, 'tools_cost': 0, 'video_cost': 0 }, 'created': 1766026675, 'discounted': '1', 'id': 'chatcmpl-202512180257506444719362giBMqDX', 'model': 'gemini-2.5-flash-preview-09-2025', 'object': 'chat.completion', 'request_id': '8dce2dd0fd4c4bfeb4374df8fb32a8a6', 'usage': { 'completion_tokens': 1133, 'input_tokens': 0, 'output_tokens': 0, 'prompt_tokens': 8, 'prompt_tokens_details': { 'text_tokens': 8 }, 'server_tool_use': { 'web_search_requests': '' }, 'total_tokens': 1141, 'ttft': 0 } }
AI 모델 토큰 사용 추적
By 앤드류 젱 •

엔터프라이즈 LLM 라우팅의 복잡성 관리

엔터프라이즈 LLM 라우팅의 복잡성 관리

원라우터 앤트로픽 클로드 API

원라우터 앤트로픽 클로드 API

원라우터 OpenAI 응답 API

원라우터 OpenAI 응답 API