تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تعالج نماذج Gemini المدخلات والمخرجات في وحدات تُعرف باسم الرموز المميزة.
يمكن أن تكون الرموز المميزة أحرفًا مفردة مثل z أو كلمات كاملة مثل cat. يتم تقسيم الكلمات الطويلة إلى عدة رموز مميزة. تُعرف مجموعة جميع الرموز المميزة التي يستخدمها النموذج باسم المفردات، وتُعرف عملية تقسيم النص إلى رموز مميزة باسم التقطيع إلى رموز مميزة.
بالنسبة إلى طُرز Gemini، يعادل الرمز المميز حوالي 4 أحرف.
يساوي 100 رمز مميز حوالي 60 إلى 80 كلمة إنجليزية.
يحتوي كل نموذج على الحد الأقصى لعدد الرموز المميزة التي يمكنه معالجتها في الطلب والاستجابة. من خلال معرفة عدد الرموز المميزة في طلبك، يمكنك معرفة ما إذا كنت قد تجاوزت هذا الحدّ. بالإضافة إلى ذلك، يتم تحديد تكلفة الطلب جزئيًا من خلال عدد الرموز المميزة الخاصة بالمدخلات والمخرجات، لذا قد يكون من المفيد معرفة كيفية احتساب الرموز المميزة.
يُرجى العِلم أنّ الطرازَين Gemini 1.0 و1.5 كانا يتيحان أيضًا احتساب "الأحرف القابلة للفوترة" وتحديد أسعارها، ولكن بما أنّ هذه الطُرز إما تم إيقافها نهائيًا أو سيتم إيقافها قريبًا، لا تتضمّن هذه الصفحة أي معلومات حول الأحرف القابلة للفوترة.
النماذج المتوافقة
gemini-2.5-pro
gemini-2.5-flash
gemini-2.5-flash-lite
gemini-2.0-flash-001 (والاسم المستعار gemini-2.0-flash الذي يتم تعديله تلقائيًا)
gemini-2.0-flash-lite-001 (والاسم المستعار الذي يتم تعديله تلقائيًا gemini-2.0-flash-lite)
gemini-2.0-flash-preview-image-generation
خيارات احتساب الرموز المميزة
يتم تقسيم جميع المدخلات والمخرجات الخاصة بـ Gemini API إلى رموز مميزة، بما في ذلك النصوص وملفات الصور وغيرها من الوسائط غير النصية. في ما يلي خيارات احتساب الرموز المميزة:
تحقَّق من عدد الرموز المميّزة لطلباتك فقط (قبل إرسالها إلى النموذج).
استدعاء countTokens مع إدخال الطلب
قبل إرساله إلى النموذج تعرض هذه السمة ما يلي:
total_tokens: عدد الرموز المميّزة للمدخلات فقط
تحقَّق من عدد الرموز المميزة لكل من طلباتك وردودك.
استخدِم السمة usageMetadata في عنصر الردّ.
ويشمل ذلك ما يلي:
prompt_token_count: عدد الرموز المميّزة في الإدخال فقط
candidates_token_count: عدد الرموز المميزة في الناتج فقط
(لا يشمل الرموز المميزة الخاصة بالتفكير)
thoughts_token_count: عدد الرموز المميزة الخاصة بالتفكير
المستخدَمة لإنشاء الرد
total_token_count: إجمالي عدد الرموز المميّزة لكلّ من الإدخال والإخراج (بما في ذلك أي رموز مميّزة خاصة بالتفكير)
عند بث الناتج، لا تظهر السمة usageMetadata إلا في آخر جزء من البث. يتم استخدام nil مع الأجزاء المتوسطة.
تجدُر الإشارة إلى النقاط التالية بشأن الخيارات المذكورة أعلاه:
لن يتم احتساب عدد الصور المدخلة أو عدد الثواني في ملفات الفيديو أو الملفات الصوتية المدخلة. ومع ذلك، فإنّ عدد الرموز المميزة لكل من هذه الوسائط سيتناسب طرديًا مع هذه القيم.
يشمل عدد الرموز المميزة للإدخال الطلب (النص وأي ملفات إدخال) بالإضافة إلى أي تعليمات وأدوات خاصة بالنظام.
لا يتضمّن عدد الرموز المميزة للناتج أي رموز مميزة للتفكير، بل يتم توفيرها في حقل منفصل.
الاتصال countTokens: لا يتم تحصيل أي رسوم مقابل الاتصال countTokens
(واجهة برمجة التطبيقات Count Tokens). الحد الأقصى للحصة المتاحة لواجهة برمجة التطبيقات Count Tokens هو 3,000 طلب في الدقيقة.
استخدام السمة usageMetadata: يتم عرض هذه السمة دائمًا كجزء من الاستجابة ولا تتسبّب في أي رموز مميّزة أو رسوم.
معلومات إضافية
في ما يلي بعض المعلومات الإضافية عند التعامل مع أنواع معيّنة من الطلبات.
احتساب الرموز المميزة للإدخال النصي
لا تتوفّر معلومات إضافية.
احتساب الرموز المميزة المتعددة الأدوار (المحادثة)
يُرجى ملاحظة ما يلي عند الاتصال بـ countTokens أثناء استخدام المحادثة:
إذا طلبت countTokens مع سجلّ المحادثة، سيتم عرض إجمالي عدد الرموز المميزة من كلا الدورين في المحادثة (total_tokens).
لمعرفة حجم الدور التالي في المحادثة، عليك إضافته إلى السجلّ عند طلب countTokens.
عدّ الرموز المميزة للإدخال المتعدد الوسائط
تجدُر الإشارة إلى النقاط التالية حول احتساب الرموز المميزة باستخدام الإدخال المتعدّد الوسائط:
يمكنك اختياريًا استدعاء countTokens على النص والملف بشكل منفصل.
بالنسبة إلى خيارَي احتساب الرموز المميزة، ستحصل على عدد الرموز المميزة نفسه سواء قدّمت الملف كبيانات مضمّنة أو باستخدام عنوان URL الخاص به.
ملفات إدخال الصور
يتم تحويل ملفات إدخال الصور إلى رموز مميزة استنادًا إلى أبعادها:
مدخلات الصور التي يقل كلا بُعدَيها عن 384 بكسل أو يساويهما: يتم احتساب 258 رمزًا مميزًا لكل صورة.
مدخلات الصور التي تكون أكبر في أحد البُعدَين أو كليهما: يتم اقتصاص كل صورة وتغيير حجمها حسب الحاجة إلى مربّعات بحجم 768 × 768 بكسل، ثم يتم احتساب كل مربّع على أنّه 258 رمزًا مميزًا.
ملفات إدخال الفيديو والصوت
يتم تحويل ملفات إدخال الفيديو والصوت إلى رموز مميزة بمعدلات ثابتة على النحو التالي:
الفيديو: 263 رمزًا مميزًا في الثانية
الصوت: 32 رمزًا مميزًا في الثانية
ملفات إدخال المستندات (مثل ملفات PDF)
يتم التعامل مع ملفات PDF المدخلة على أنّها صور، لذا يتم تقسيم كل صفحة من ملف PDF إلى رموز مميزة بالطريقة نفسها التي يتم بها تقسيم الصور.
تاريخ التعديل الأخير: 2025-09-05 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-09-05 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["\u003cbr /\u003e\n\nGemini models process input and output in units called *tokens*.\n\nTokens can be single characters like `z` or whole words like `cat`. Long words\nare broken up into several tokens. The set of all tokens used by the model is\ncalled the vocabulary, and the process of splitting text into tokens is called\n*tokenization*.\n\nFor Gemini models, a token is equivalent to about 4 characters.\n100 tokens is equal to about 60-80 English words.\n\nEach model has a\n[maximum number of tokens](/docs/ai-logic/models#specs-and-limitations-comparison)\nthat it can handle in a prompt and response. Knowing the token count of your\nprompt lets you know if you've exceeded this limit. Additionally, the cost of a\nrequest is determined in part by the number of input and output tokens, so\nknowing how to count tokens can be helpful.\n| **Tip:** To control the number of tokens used for generating a response (and thus control costs), you can set the [thinking budget](/docs/ai-logic/thinking) (for 2.5 models only) and the `maxOutputTokens` (all Gemini models) in the [model's configuration](/docs/ai-logic/model-parameters#gemini).\n\nNote that Gemini 1.0 and 1.5 models also supported a\n\"billable characters\" count and pricing, but since those models are all either\nretired or soon-to-be-retired, this page does not describe anything about\nbillable characters.\n\nSupported models\n\n- `gemini-2.5-pro`\n- `gemini-2.5-flash`\n- `gemini-2.5-flash-lite`\n- `gemini-2.0-flash-001` (and its auto-updated alias `gemini-2.0-flash`)\n- `gemini-2.0-flash-lite-001` (and its auto-updated alias `gemini-2.0-flash-lite`)\n- `gemini-2.0-flash-preview-image-generation`\n\n| **Note** : Although all generative models process input and output as tokens, this page and its token counting options are specific only to the *Gemini* models listed above. Specifically, note that the Gemini 2.0 Flash Live model is not supported.\n|\n| For Imagen models, pricing and limits aren't based on tokens.\n\nOptions for counting tokens\n\nAll input and output for the Gemini API is tokenized, including text, image\nfiles, and other non-text modalities. Here are the options for counting tokens:\n\nCheck the token count for your *requests only* (before sending them\nto the model).\n: Call `countTokens` with the input of the request\n *before* sending it to the model. This returns:\n\n - `total_tokens`: token count of the *input only*\n\nCheck the token count for *both your requests and responses*.\n: Use the `usageMetadata` attribute on the response object.\n This includes:\n\n - `prompt_token_count`: token count of the input only\n - `candidates_token_count`: token count of the output only (does not include thinking tokens)\n - `thoughts_token_count`: token count of any thinking tokens used to generate the response\n - `total_token_count`: total count of tokens for *both* the input and the output (includes any thinking tokens)\n\n\n When streaming output, the `usageMetadata` attribute only\n appears on the last chunk of the stream. It's `nil` for\n intermediate chunks.\n\nNote the following points about the options above:\n\n- They will *not* count the number of input images or the number of seconds in video or audio input files. However, the token count for each of these modalities will *correlate* with these values.\n- The input token count includes the prompt (text and any input files) as well as any system instructions and tools.\n- The output token count does not include any thinking tokens; those are provided in a separate field.\n- Review the [additional information specific to each type of request](#additional-information) later on this page.\n\nPricing for these options\n\n- Calling `countTokens`: There's no charge for calling `countTokens`\n (the Count Tokens API). The maximum quota for the Count Tokens API is 3000\n requests per minute (RPM).\n\n- Using the `usageMetadata` attribute: This attribute is always returned as\n part of the response and doesn't incur any tokens or charge itself.\n\nAdditional information\n\nHere's some additional information when working with specific types of requests.\n\nCount text input tokens\n\nNo additional information.\n\nCount multi-turn (chat) tokens\n\nNote the following for calling `countTokens` when using chat:\n\n- If you call `countTokens` with the chat history, it returns the total token count from both roles in the chat (`total_tokens`).\n- To understand how big your next conversational turn will be, you need to append it to the history when you call `countTokens`.\n\nCount multimodal input tokens\n\nNote the following points about counting tokens with multimodal input:\n\n- You can optionally call `countTokens` on the text and the file separately.\n- For both token counting options, you'll get the same token count whether you provide the file as inline data or using its URL.\n\nImage input files\n\nImage input files are converted to tokens based on their dimensions:\n\n- Image inputs with *both* dimensions less than or equal to 384 pixels: each image is counted as 258 tokens.\n- Image inputs that are larger in one or both dimensions: each image is cropped and scaled as needed into tiles of 768x768 pixels, and then each tile is counted as 258 tokens.\n\nVideo and audio input files\n\nVideo and audio input files are converted to tokens at the following fixed\nrates:\n\n- Video: 263 tokens per second\n- Audio: 32 tokens per second\n\nDocument (like PDFs) input files\n\nPDF input files are treated as images, so each page of a PDF is tokenized in the\nsame way as an image."]]