Skip to content

Commit 22573fb

Browse files
[AI] Remove deprecated totalBillableCharacters property (#15056)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent ed8b815 commit 22573fb

File tree

5 files changed

+4
-48
lines changed

5 files changed

+4
-48
lines changed

FirebaseAI/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Unreleased
2+
- [removed] Removed `CountTokensResponse.totalBillableCharacters` which was
3+
deprecated in 11.15.0. Use `totalTokens` instead. (#15056)
4+
15
# 11.15.0
26
- [fixed] Fixed `Sendable` warnings introduced in the Xcode 26 beta. (#14947)
37
- [added] Added support for setting `title` in string, number and array `Schema`

FirebaseAI/Sources/Types/Internal/Requests/CountTokensRequest.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,11 @@ extension CountTokensRequest: GenerativeAIRequest {
3939
/// The model's response to a count tokens request.
4040
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
4141
public struct CountTokensResponse: Sendable {
42-
/// Container for deprecated properties or methods.
43-
///
44-
/// This workaround allows deprecated fields to be referenced internally (for example in the
45-
/// `init(from:)` constructor) without introducing compiler warnings.
46-
struct Deprecated {
47-
let totalBillableCharacters: Int?
48-
}
49-
5042
/// The total number of tokens in the input given to the model as a prompt.
5143
public let totalTokens: Int
5244

53-
/// The total number of billable characters in the text input given to the model as a prompt.
54-
///
55-
/// > Important: This does not include billable image, video or other non-text input. See
56-
/// [Vertex AI pricing](https://firebase.google.com/docs/vertex-ai/pricing) for details.
57-
@available(*, deprecated, message: """
58-
Use `totalTokens` instead; Gemini 2.0 series models and newer are always billed by token count.
59-
""")
60-
public var totalBillableCharacters: Int? { deprecated.totalBillableCharacters }
61-
6245
/// The breakdown, by modality, of how many tokens are consumed by the prompt.
6346
public let promptTokensDetails: [ModalityTokenCount]
64-
65-
/// Deprecated properties or methods.
66-
let deprecated: Deprecated
6747
}
6848

6949
// MARK: - Codable Conformances
@@ -112,7 +92,6 @@ extension CountTokensRequest: Encodable {
11292
extension CountTokensResponse: Decodable {
11393
enum CodingKeys: CodingKey {
11494
case totalTokens
115-
case totalBillableCharacters
11695
case promptTokensDetails
11796
}
11897

@@ -121,8 +100,5 @@ extension CountTokensResponse: Decodable {
121100
totalTokens = try container.decodeIfPresent(Int.self, forKey: .totalTokens) ?? 0
122101
promptTokensDetails =
123102
try container.decodeIfPresent([ModalityTokenCount].self, forKey: .promptTokensDetails) ?? []
124-
let totalBillableCharacters =
125-
try container.decodeIfPresent(Int.self, forKey: .totalBillableCharacters)
126-
deprecated = CountTokensResponse.Deprecated(totalBillableCharacters: totalBillableCharacters)
127103
}
128104
}

FirebaseAI/Tests/TestApp/Tests/Integration/CountTokensIntegrationTests.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ struct CountTokensIntegrationTests {
5757
let response = try await model.countTokens(prompt)
5858

5959
#expect(response.totalTokens == 6)
60-
switch config.apiConfig.service {
61-
case .vertexAI:
62-
#expect(response.deprecated.totalBillableCharacters == 16)
63-
case .googleAI:
64-
#expect(response.deprecated.totalBillableCharacters == nil)
65-
}
6660
#expect(response.promptTokensDetails.count == 1)
6761
let promptTokensDetails = try #require(response.promptTokensDetails.first)
6862
#expect(promptTokensDetails.modality == .text)
@@ -81,12 +75,6 @@ struct CountTokensIntegrationTests {
8175
let response = try await model.countTokens("What is your favourite colour?")
8276

8377
#expect(response.totalTokens == 14)
84-
switch config.apiConfig.service {
85-
case .vertexAI:
86-
#expect(response.deprecated.totalBillableCharacters == 61)
87-
case .googleAI:
88-
#expect(response.deprecated.totalBillableCharacters == nil)
89-
}
9078
#expect(response.promptTokensDetails.count == 1)
9179
let promptTokensDetails = try #require(response.promptTokensDetails.first)
9280
#expect(promptTokensDetails.modality == .text)
@@ -115,12 +103,10 @@ struct CountTokensIntegrationTests {
115103
switch config.apiConfig.service {
116104
case .vertexAI:
117105
#expect(response.totalTokens == 65)
118-
#expect(response.deprecated.totalBillableCharacters == 170)
119106
case .googleAI:
120107
// The Developer API erroneously ignores the `responseSchema` when counting tokens, resulting
121108
// in a lower total count than Vertex AI.
122109
#expect(response.totalTokens == 34)
123-
#expect(response.deprecated.totalBillableCharacters == nil)
124110
}
125111
#expect(response.promptTokensDetails.count == 1)
126112
let promptTokensDetails = try #require(response.promptTokensDetails.first)

FirebaseAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ final class IntegrationTests: XCTestCase {
8585
let response = try await model.countTokens(prompt)
8686

8787
XCTAssertEqual(response.totalTokens, 14)
88-
XCTAssertEqual(response.deprecated.totalBillableCharacters, 51)
8988
XCTAssertEqual(response.promptTokensDetails.count, 1)
9089
let promptTokensDetails = try XCTUnwrap(response.promptTokensDetails.first)
9190
XCTAssertEqual(promptTokensDetails.modality, .text)
@@ -102,7 +101,6 @@ final class IntegrationTests: XCTestCase {
102101
let response = try await model.countTokens(image)
103102

104103
XCTAssertEqual(response.totalTokens, 266)
105-
XCTAssertEqual(response.deprecated.totalBillableCharacters, 35)
106104
XCTAssertEqual(response.promptTokensDetails.count, 2) // Image prompt + system instruction
107105
let textPromptTokensDetails = try XCTUnwrap(response.promptTokensDetails.first {
108106
$0.modality == .text
@@ -122,7 +120,6 @@ final class IntegrationTests: XCTestCase {
122120
let response = try await model.countTokens(fileData)
123121

124122
XCTAssertEqual(response.totalTokens, 266)
125-
XCTAssertEqual(response.deprecated.totalBillableCharacters, 35)
126123
XCTAssertEqual(response.promptTokensDetails.count, 2) // Image prompt + system instruction
127124
let textPromptTokensDetails = try XCTUnwrap(response.promptTokensDetails.first {
128125
$0.modality == .text
@@ -141,7 +138,6 @@ final class IntegrationTests: XCTestCase {
141138
let response = try await model.countTokens(fileData)
142139

143140
XCTAssertEqual(response.totalTokens, 266)
144-
XCTAssertEqual(response.deprecated.totalBillableCharacters, 35)
145141
}
146142

147143
func testCountTokens_image_fileData_requiresUserAuth_userSignedIn() async throws {
@@ -152,7 +148,6 @@ final class IntegrationTests: XCTestCase {
152148
let response = try await model.countTokens(fileData)
153149

154150
XCTAssertEqual(response.totalTokens, 266)
155-
XCTAssertEqual(response.deprecated.totalBillableCharacters, 35)
156151
}
157152

158153
func testCountTokens_image_fileData_requiresUserAuth_wrongUser_permissionDenied() async throws {
@@ -193,7 +188,6 @@ final class IntegrationTests: XCTestCase {
193188
])
194189

195190
XCTAssertGreaterThan(response.totalTokens, 0)
196-
XCTAssertEqual(response.deprecated.totalBillableCharacters, 71)
197191
XCTAssertEqual(response.promptTokensDetails.count, 1)
198192
let promptTokensDetails = try XCTUnwrap(response.promptTokensDetails.first)
199193
XCTAssertEqual(promptTokensDetails.modality, .text)

FirebaseAI/Tests/Unit/GenerativeModelVertexAITests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,6 @@ final class GenerativeModelVertexAITests: XCTestCase {
15171517
let response = try await model.countTokens("Why is the sky blue?")
15181518

15191519
XCTAssertEqual(response.totalTokens, 6)
1520-
XCTAssertEqual(response.deprecated.totalBillableCharacters, 16)
15211520
}
15221521

15231522
func testCountTokens_succeeds_detailed() async throws {
@@ -1530,7 +1529,6 @@ final class GenerativeModelVertexAITests: XCTestCase {
15301529
let response = try await model.countTokens("Why is the sky blue?")
15311530

15321531
XCTAssertEqual(response.totalTokens, 1837)
1533-
XCTAssertEqual(response.deprecated.totalBillableCharacters, 117)
15341532
XCTAssertEqual(response.promptTokensDetails.count, 2)
15351533
XCTAssertEqual(response.promptTokensDetails[0].modality, .image)
15361534
XCTAssertEqual(response.promptTokensDetails[0].tokenCount, 1806)
@@ -1577,7 +1575,6 @@ final class GenerativeModelVertexAITests: XCTestCase {
15771575
let response = try await model.countTokens("Why is the sky blue?")
15781576

15791577
XCTAssertEqual(response.totalTokens, 6)
1580-
XCTAssertEqual(response.deprecated.totalBillableCharacters, 16)
15811578
}
15821579

15831580
func testCountTokens_succeeds_noBillableCharacters() async throws {
@@ -1590,7 +1587,6 @@ final class GenerativeModelVertexAITests: XCTestCase {
15901587
let response = try await model.countTokens(InlineDataPart(data: Data(), mimeType: "image/jpeg"))
15911588

15921589
XCTAssertEqual(response.totalTokens, 258)
1593-
XCTAssertNil(response.deprecated.totalBillableCharacters)
15941590
}
15951591

15961592
func testCountTokens_modelNotFound() async throws {

0 commit comments

Comments
 (0)