Skip to content

Commit ad25023

Browse files
stainless-app[bot]felixfbecker
authored andcommitted
feat(api): add support for speed mode
1 parent 497621a commit ad25023

21 files changed

+819
-9
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 34
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-267f913f89364cb8df3a758335a974b43eb98019a8ceef0a9b0a94ef34c2a3b5.yml
3-
openapi_spec_hash: aa708f3d3bc54992526cbf5894427446
4-
config_hash: d56fbaeeb3934b1a3b374590c9837ddd
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-fee5dc365a4948e68639582c5301d4d0666c7d85a11628d7917e1477f76d3da1.yml
3+
openapi_spec_hash: d5543958074cd2bd74096cd69f3bb4f9
4+
config_hash: c4802b6c7f8ffae62f7d73b2ac61e635

anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/AnthropicBeta.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel
6060

6161
@JvmField val SKILLS_2025_10_02 = of("skills-2025-10-02")
6262

63+
@JvmField val FAST_MODE_2026_02_01 = of("fast-mode-2026-02-01")
64+
6365
@JvmStatic fun of(value: String) = AnthropicBeta(JsonField.of(value))
6466
}
6567

@@ -84,6 +86,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel
8486
CONTEXT_MANAGEMENT_2025_06_27,
8587
MODEL_CONTEXT_WINDOW_EXCEEDED_2025_08_26,
8688
SKILLS_2025_10_02,
89+
FAST_MODE_2026_02_01,
8790
}
8891

8992
/**
@@ -115,6 +118,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel
115118
CONTEXT_MANAGEMENT_2025_06_27,
116119
MODEL_CONTEXT_WINDOW_EXCEEDED_2025_08_26,
117120
SKILLS_2025_10_02,
121+
FAST_MODE_2026_02_01,
118122
/**
119123
* An enum member indicating that [AnthropicBeta] was instantiated with an unknown value.
120124
*/
@@ -150,6 +154,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel
150154
MODEL_CONTEXT_WINDOW_EXCEEDED_2025_08_26 ->
151155
Value.MODEL_CONTEXT_WINDOW_EXCEEDED_2025_08_26
152156
SKILLS_2025_10_02 -> Value.SKILLS_2025_10_02
157+
FAST_MODE_2026_02_01 -> Value.FAST_MODE_2026_02_01
153158
else -> Value._UNKNOWN
154159
}
155160

@@ -183,6 +188,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel
183188
MODEL_CONTEXT_WINDOW_EXCEEDED_2025_08_26 ->
184189
Known.MODEL_CONTEXT_WINDOW_EXCEEDED_2025_08_26
185190
SKILLS_2025_10_02 -> Known.SKILLS_2025_10_02
191+
FAST_MODE_2026_02_01 -> Known.FAST_MODE_2026_02_01
186192
else -> throw AnthropicInvalidDataException("Unknown AnthropicBeta: $value")
187193
}
188194

anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaUsage.kt

Lines changed: 171 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private constructor(
4343
private val outputTokens: JsonField<Long>,
4444
private val serverToolUse: JsonField<BetaServerToolUsage>,
4545
private val serviceTier: JsonField<ServiceTier>,
46+
private val speed: JsonField<Speed>,
4647
private val additionalProperties: MutableMap<String, JsonValue>,
4748
) {
4849

@@ -75,6 +76,7 @@ private constructor(
7576
@JsonProperty("service_tier")
7677
@ExcludeMissing
7778
serviceTier: JsonField<ServiceTier> = JsonMissing.of(),
79+
@JsonProperty("speed") @ExcludeMissing speed: JsonField<Speed> = JsonMissing.of(),
7880
) : this(
7981
cacheCreation,
8082
cacheCreationInputTokens,
@@ -85,6 +87,7 @@ private constructor(
8587
outputTokens,
8688
serverToolUse,
8789
serviceTier,
90+
speed,
8891
mutableMapOf(),
8992
)
9093

@@ -170,6 +173,14 @@ private constructor(
170173
*/
171174
fun serviceTier(): Optional<ServiceTier> = serviceTier.getOptional("service_tier")
172175

176+
/**
177+
* The inference speed mode used for this request.
178+
*
179+
* @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the
180+
* server responded with an unexpected value).
181+
*/
182+
fun speed(): Optional<Speed> = speed.getOptional("speed")
183+
173184
/**
174185
* Returns the raw JSON value of [cacheCreation].
175186
*
@@ -251,6 +262,13 @@ private constructor(
251262
@ExcludeMissing
252263
fun _serviceTier(): JsonField<ServiceTier> = serviceTier
253264

265+
/**
266+
* Returns the raw JSON value of [speed].
267+
*
268+
* Unlike [speed], this method doesn't throw if the JSON field has an unexpected type.
269+
*/
270+
@JsonProperty("speed") @ExcludeMissing fun _speed(): JsonField<Speed> = speed
271+
254272
@JsonAnySetter
255273
private fun putAdditionalProperty(key: String, value: JsonValue) {
256274
additionalProperties.put(key, value)
@@ -279,6 +297,7 @@ private constructor(
279297
* .outputTokens()
280298
* .serverToolUse()
281299
* .serviceTier()
300+
* .speed()
282301
* ```
283302
*/
284303
@JvmStatic fun builder() = Builder()
@@ -296,6 +315,7 @@ private constructor(
296315
private var outputTokens: JsonField<Long>? = null
297316
private var serverToolUse: JsonField<BetaServerToolUsage>? = null
298317
private var serviceTier: JsonField<ServiceTier>? = null
318+
private var speed: JsonField<Speed>? = null
299319
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
300320

301321
@JvmSynthetic
@@ -309,6 +329,7 @@ private constructor(
309329
outputTokens = betaUsage.outputTokens
310330
serverToolUse = betaUsage.serverToolUse
311331
serviceTier = betaUsage.serviceTier
332+
speed = betaUsage.speed
312333
additionalProperties = betaUsage.additionalProperties.toMutableMap()
313334
}
314335

@@ -523,6 +544,20 @@ private constructor(
523544
this.serviceTier = serviceTier
524545
}
525546

547+
/** The inference speed mode used for this request. */
548+
fun speed(speed: Speed?) = speed(JsonField.ofNullable(speed))
549+
550+
/** Alias for calling [Builder.speed] with `speed.orElse(null)`. */
551+
fun speed(speed: Optional<Speed>) = speed(speed.getOrNull())
552+
553+
/**
554+
* Sets [Builder.speed] to an arbitrary JSON value.
555+
*
556+
* You should usually call [Builder.speed] with a well-typed [Speed] value instead. This
557+
* method is primarily for setting the field to an undocumented or not yet supported value.
558+
*/
559+
fun speed(speed: JsonField<Speed>) = apply { this.speed = speed }
560+
526561
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
527562
this.additionalProperties.clear()
528563
putAllAdditionalProperties(additionalProperties)
@@ -558,6 +593,7 @@ private constructor(
558593
* .outputTokens()
559594
* .serverToolUse()
560595
* .serviceTier()
596+
* .speed()
561597
* ```
562598
*
563599
* @throws IllegalStateException if any required field is unset.
@@ -573,6 +609,7 @@ private constructor(
573609
checkRequired("outputTokens", outputTokens),
574610
checkRequired("serverToolUse", serverToolUse),
575611
checkRequired("serviceTier", serviceTier),
612+
checkRequired("speed", speed),
576613
additionalProperties.toMutableMap(),
577614
)
578615
}
@@ -593,6 +630,7 @@ private constructor(
593630
outputTokens()
594631
serverToolUse().ifPresent { it.validate() }
595632
serviceTier().ifPresent { it.validate() }
633+
speed().ifPresent { it.validate() }
596634
validated = true
597635
}
598636

@@ -619,7 +657,8 @@ private constructor(
619657
(iterations.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
620658
(if (outputTokens.asKnown().isPresent) 1 else 0) +
621659
(serverToolUse.asKnown().getOrNull()?.validity() ?: 0) +
622-
(serviceTier.asKnown().getOrNull()?.validity() ?: 0)
660+
(serviceTier.asKnown().getOrNull()?.validity() ?: 0) +
661+
(speed.asKnown().getOrNull()?.validity() ?: 0)
623662

624663
/** Token usage for a sampling iteration. */
625664
@JsonDeserialize(using = BetaIterationsUsageItems.Deserializer::class)
@@ -973,6 +1012,134 @@ private constructor(
9731012
override fun toString() = value.toString()
9741013
}
9751014

1015+
/** The inference speed mode used for this request. */
1016+
class Speed @JsonCreator private constructor(private val value: JsonField<String>) : Enum {
1017+
1018+
/**
1019+
* Returns this class instance's raw value.
1020+
*
1021+
* This is usually only useful if this instance was deserialized from data that doesn't
1022+
* match any known member, and you want to know that value. For example, if the SDK is on an
1023+
* older version than the API, then the API may respond with new members that the SDK is
1024+
* unaware of.
1025+
*/
1026+
@com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value
1027+
1028+
companion object {
1029+
1030+
@JvmField val STANDARD = of("standard")
1031+
1032+
@JvmField val FAST = of("fast")
1033+
1034+
@JvmStatic fun of(value: String) = Speed(JsonField.of(value))
1035+
}
1036+
1037+
/** An enum containing [Speed]'s known values. */
1038+
enum class Known {
1039+
STANDARD,
1040+
FAST,
1041+
}
1042+
1043+
/**
1044+
* An enum containing [Speed]'s known values, as well as an [_UNKNOWN] member.
1045+
*
1046+
* An instance of [Speed] can contain an unknown value in a couple of cases:
1047+
* - It was deserialized from data that doesn't match any known member. For example, if the
1048+
* SDK is on an older version than the API, then the API may respond with new members that
1049+
* the SDK is unaware of.
1050+
* - It was constructed with an arbitrary value using the [of] method.
1051+
*/
1052+
enum class Value {
1053+
STANDARD,
1054+
FAST,
1055+
/** An enum member indicating that [Speed] was instantiated with an unknown value. */
1056+
_UNKNOWN,
1057+
}
1058+
1059+
/**
1060+
* Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
1061+
* if the class was instantiated with an unknown value.
1062+
*
1063+
* Use the [known] method instead if you're certain the value is always known or if you want
1064+
* to throw for the unknown case.
1065+
*/
1066+
fun value(): Value =
1067+
when (this) {
1068+
STANDARD -> Value.STANDARD
1069+
FAST -> Value.FAST
1070+
else -> Value._UNKNOWN
1071+
}
1072+
1073+
/**
1074+
* Returns an enum member corresponding to this class instance's value.
1075+
*
1076+
* Use the [value] method instead if you're uncertain the value is always known and don't
1077+
* want to throw for the unknown case.
1078+
*
1079+
* @throws AnthropicInvalidDataException if this class instance's value is a not a known
1080+
* member.
1081+
*/
1082+
fun known(): Known =
1083+
when (this) {
1084+
STANDARD -> Known.STANDARD
1085+
FAST -> Known.FAST
1086+
else -> throw AnthropicInvalidDataException("Unknown Speed: $value")
1087+
}
1088+
1089+
/**
1090+
* Returns this class instance's primitive wire representation.
1091+
*
1092+
* This differs from the [toString] method because that method is primarily for debugging
1093+
* and generally doesn't throw.
1094+
*
1095+
* @throws AnthropicInvalidDataException if this class instance's value does not have the
1096+
* expected primitive type.
1097+
*/
1098+
fun asString(): String =
1099+
_value().asString().orElseThrow {
1100+
AnthropicInvalidDataException("Value is not a String")
1101+
}
1102+
1103+
private var validated: Boolean = false
1104+
1105+
fun validate(): Speed = apply {
1106+
if (validated) {
1107+
return@apply
1108+
}
1109+
1110+
known()
1111+
validated = true
1112+
}
1113+
1114+
fun isValid(): Boolean =
1115+
try {
1116+
validate()
1117+
true
1118+
} catch (e: AnthropicInvalidDataException) {
1119+
false
1120+
}
1121+
1122+
/**
1123+
* Returns a score indicating how many valid values are contained in this object
1124+
* recursively.
1125+
*
1126+
* Used for best match union deserialization.
1127+
*/
1128+
@JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
1129+
1130+
override fun equals(other: Any?): Boolean {
1131+
if (this === other) {
1132+
return true
1133+
}
1134+
1135+
return other is Speed && value == other.value
1136+
}
1137+
1138+
override fun hashCode() = value.hashCode()
1139+
1140+
override fun toString() = value.toString()
1141+
}
1142+
9761143
override fun equals(other: Any?): Boolean {
9771144
if (this === other) {
9781145
return true
@@ -988,6 +1155,7 @@ private constructor(
9881155
outputTokens == other.outputTokens &&
9891156
serverToolUse == other.serverToolUse &&
9901157
serviceTier == other.serviceTier &&
1158+
speed == other.speed &&
9911159
additionalProperties == other.additionalProperties
9921160
}
9931161

@@ -1002,12 +1170,13 @@ private constructor(
10021170
outputTokens,
10031171
serverToolUse,
10041172
serviceTier,
1173+
speed,
10051174
additionalProperties,
10061175
)
10071176
}
10081177

10091178
override fun hashCode(): Int = hashCode
10101179

10111180
override fun toString() =
1012-
"BetaUsage{cacheCreation=$cacheCreation, cacheCreationInputTokens=$cacheCreationInputTokens, cacheReadInputTokens=$cacheReadInputTokens, inferenceGeo=$inferenceGeo, inputTokens=$inputTokens, iterations=$iterations, outputTokens=$outputTokens, serverToolUse=$serverToolUse, serviceTier=$serviceTier, additionalProperties=$additionalProperties}"
1181+
"BetaUsage{cacheCreation=$cacheCreation, cacheCreationInputTokens=$cacheCreationInputTokens, cacheReadInputTokens=$cacheReadInputTokens, inferenceGeo=$inferenceGeo, inputTokens=$inputTokens, iterations=$iterations, outputTokens=$outputTokens, serverToolUse=$serverToolUse, serviceTier=$serviceTier, speed=$speed, additionalProperties=$additionalProperties}"
10131182
}

0 commit comments

Comments
 (0)