Skip to content

Commit

Permalink
feat(api): general availability updates (#21)
Browse files Browse the repository at this point in the history
The following APIs are now GA and have been moved out of the beta namespace:
- Prompt caching
- Token counting
- PDF Support
- The Batch API
This commit also adds new endpoints for listing available models.
https://docs.anthropic.com/en/release-notes/api
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Dec 17, 2024
1 parent bbe65de commit a44228a
Show file tree
Hide file tree
Showing 153 changed files with 12,267 additions and 4,768 deletions.
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 9
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-73443ebfebee64b8ec0ebbacd2521d6b6aa900e9526ec97abdcbcff0c0955d9b.yml
configured_endpoints: 17
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-be055148d227480fcacc9086c37ac8009dcb487731069ada51af35044f65bee4.yml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ if (field.isMissing()) {
Sometimes, the server response may include additional properties that are not yet available in this library's types. You can access them using the model's `_additionalProperties` method:

```java
JsonValue secret = completion._additionalProperties().get("secret_field");
JsonValue secret = apiErrorObject._additionalProperties().get("secret_field");
```

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.anthropic.client
import com.anthropic.services.blocking.BetaService
import com.anthropic.services.blocking.CompletionService
import com.anthropic.services.blocking.MessageService
import com.anthropic.services.blocking.ModelService

interface AnthropicClient {

Expand All @@ -14,5 +15,7 @@ interface AnthropicClient {

fun messages(): MessageService

fun models(): ModelService

fun beta(): BetaService
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.anthropic.client
import com.anthropic.services.async.BetaServiceAsync
import com.anthropic.services.async.CompletionServiceAsync
import com.anthropic.services.async.MessageServiceAsync
import com.anthropic.services.async.ModelServiceAsync

interface AnthropicClientAsync {

Expand All @@ -14,5 +15,7 @@ interface AnthropicClientAsync {

fun messages(): MessageServiceAsync

fun models(): ModelServiceAsync

fun beta(): BetaServiceAsync
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.anthropic.services.async.CompletionServiceAsync
import com.anthropic.services.async.CompletionServiceAsyncImpl
import com.anthropic.services.async.MessageServiceAsync
import com.anthropic.services.async.MessageServiceAsyncImpl
import com.anthropic.services.async.ModelServiceAsync
import com.anthropic.services.async.ModelServiceAsyncImpl

class AnthropicClientAsyncImpl
constructor(
Expand All @@ -35,6 +37,10 @@ constructor(
MessageServiceAsyncImpl(clientOptionsWithUserAgent)
}

private val models: ModelServiceAsync by lazy {
ModelServiceAsyncImpl(clientOptionsWithUserAgent)
}

private val beta: BetaServiceAsync by lazy { BetaServiceAsyncImpl(clientOptionsWithUserAgent) }

override fun sync(): AnthropicClient = sync
Expand All @@ -43,5 +49,7 @@ constructor(

override fun messages(): MessageServiceAsync = messages

override fun models(): ModelServiceAsync = models

override fun beta(): BetaServiceAsync = beta
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.anthropic.services.blocking.CompletionService
import com.anthropic.services.blocking.CompletionServiceImpl
import com.anthropic.services.blocking.MessageService
import com.anthropic.services.blocking.MessageServiceImpl
import com.anthropic.services.blocking.ModelService
import com.anthropic.services.blocking.ModelServiceImpl

class AnthropicClientImpl
constructor(
Expand All @@ -33,6 +35,8 @@ constructor(

private val messages: MessageService by lazy { MessageServiceImpl(clientOptionsWithUserAgent) }

private val models: ModelService by lazy { ModelServiceImpl(clientOptionsWithUserAgent) }

private val beta: BetaService by lazy { BetaServiceImpl(clientOptionsWithUserAgent) }

override fun async(): AnthropicClientAsync = async
Expand All @@ -41,5 +45,7 @@ constructor(

override fun messages(): MessageService = messages

override fun models(): ModelService = models

override fun beta(): BetaService = beta
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// File generated from our OpenAPI spec by Stainless.

package com.anthropic.models

import com.anthropic.core.Enum
import com.anthropic.core.ExcludeMissing
import com.anthropic.core.JsonField
import com.anthropic.core.JsonMissing
import com.anthropic.core.JsonValue
import com.anthropic.core.NoAutoDetect
import com.anthropic.core.toImmutable
import com.anthropic.errors.AnthropicInvalidDataException
import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonAnySetter
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import java.util.Objects

@JsonDeserialize(builder = ApiErrorObject.Builder::class)
@NoAutoDetect
class ApiErrorObject
private constructor(
private val type: JsonField<Type>,
private val message: JsonField<String>,
private val additionalProperties: Map<String, JsonValue>,
) {

private var validated: Boolean = false

fun type(): Type = type.getRequired("type")

fun message(): String = message.getRequired("message")

@JsonProperty("type") @ExcludeMissing fun _type() = type

@JsonProperty("message") @ExcludeMissing fun _message() = message

@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties

fun validate(): ApiErrorObject = apply {
if (!validated) {
type()
message()
validated = true
}
}

fun toBuilder() = Builder().from(this)

companion object {

@JvmStatic fun builder() = Builder()
}

class Builder {

private var type: JsonField<Type> = JsonMissing.of()
private var message: JsonField<String> = JsonMissing.of()
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
internal fun from(apiErrorObject: ApiErrorObject) = apply {
this.type = apiErrorObject.type
this.message = apiErrorObject.message
additionalProperties(apiErrorObject.additionalProperties)
}

fun type(type: Type) = type(JsonField.of(type))

@JsonProperty("type")
@ExcludeMissing
fun type(type: JsonField<Type>) = apply { this.type = type }

fun message(message: String) = message(JsonField.of(message))

@JsonProperty("message")
@ExcludeMissing
fun message(message: JsonField<String>) = apply { this.message = message }

fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
this.additionalProperties.clear()
this.additionalProperties.putAll(additionalProperties)
}

@JsonAnySetter
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
this.additionalProperties.put(key, value)
}

fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
this.additionalProperties.putAll(additionalProperties)
}

fun build(): ApiErrorObject =
ApiErrorObject(
type,
message,
additionalProperties.toImmutable(),
)
}

class Type
@JsonCreator
private constructor(
private val value: JsonField<String>,
) : Enum {

@com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value

companion object {

@JvmField val API_ERROR = of("api_error")

@JvmStatic fun of(value: String) = Type(JsonField.of(value))
}

enum class Known {
API_ERROR,
}

enum class Value {
API_ERROR,
_UNKNOWN,
}

fun value(): Value =
when (this) {
API_ERROR -> Value.API_ERROR
else -> Value._UNKNOWN
}

fun known(): Known =
when (this) {
API_ERROR -> Known.API_ERROR
else -> throw AnthropicInvalidDataException("Unknown Type: $value")
}

fun asString(): String = _value().asStringOrThrow()

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return /* spotless:off */ other is Type && value == other.value /* spotless:on */
}

override fun hashCode() = value.hashCode()

override fun toString() = value.toString()
}

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return /* spotless:off */ other is ApiErrorObject && type == other.type && message == other.message && additionalProperties == other.additionalProperties /* spotless:on */
}

/* spotless:off */
private val hashCode: Int by lazy { Objects.hash(type, message, additionalProperties) }
/* spotless:on */

override fun hashCode(): Int = hashCode

override fun toString() =
"ApiErrorObject{type=$type, message=$message, additionalProperties=$additionalProperties}"
}
Loading

0 comments on commit a44228a

Please sign in to comment.