The samples below show how a published SDK artifact is used:
Gradle:
implementation 'com.writer.api:sdk:0.45.2'
Maven:
<dependency>
<groupId>com.writer.api</groupId>
<artifactId>sdk</artifactId>
<version>0.45.2</version>
</dependency>
After cloning the git repository to your file system you can build the SDK artifact from source to the build
directory by running ./gradlew build
on *nix systems or gradlew.bat
on Windows systems.
If you wish to build from source and publish the SDK artifact to your local Maven repository (on your filesystem) then use the following command (after cloning the git repo locally):
On *nix:
./gradlew publishToMavenLocal -Pskip.signing
On Windows:
gradlew.bat publishToMavenLocal -Pskip.signing
Writer authenticates your API requests using your account’s API keys. If you do not include your key when making an API request, or use one that is incorrect or outdated, Writer returns an error.
Your API keys are available in the account dashboard. We include randomly generated API keys in our code examples if you are not logged in. Replace these with your own or log in to see code examples populated with your own API keys.
If you cannot see your secret API keys in the Dashboard, this means you do not have access to them. Contact your Writer account owner and ask to be added to their team as a developer.
package hello.world;
import com.writer.api.Writer;
import com.writer.api.models.operations.*;
import com.writer.api.models.operations.GetSubscriptionDetailsResponse;
import com.writer.api.models.shared.*;
import com.writer.api.models.shared.Security;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import static java.util.Map.entry;
public class Application {
public static void main(String[] args) {
try {
Writer sdk = Writer.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.organizationId(850421L)
.build();
GetSubscriptionDetailsResponse res = sdk.billing().getSubscriptionDetails()
.call();
if (res.subscriptionPublicResponseApi().isPresent()) {
// handle response
}
} catch (com.writer.api.models.errors.FailResponse e) {
// handle exception
} catch (com.writer.api.models.errors.SDKError e) {
// handle exception
} catch (Exception e) {
// handle exception
}
}
}
- getSubscriptionDetails - Get your organization subscription details
- detect - Content detector api
- check - Check your content against your preset styleguide.
- correct - Apply the style guide suggestions directly to your content.
- generateContent - Generate content using predefined templates
- listTemplates - Get a list of your existing CoWrite templates
- list - List available LLM models
- create - Create completion for LLM model
- createModelCustomizationCompletion - Create completion for LLM customization model
- create - Create model customization
- delete - Delete Model customization
- get - Get model customization
- list - List model customizations
- fetchFile - Download your fine-tuned model (available only for Palmyra Base and Palmyra Large)
- list - List users
A parameter is configured globally. This parameter must be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set organizationId
to 297548L
at SDK initialization and then you do not have to pass the same value on calls to operations like detect
. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
The following global parameter is available. The required parameter must be set when you initialize the SDK client.
Name | Type | Required | Description |
---|---|---|---|
organizationId | long | ✔️ | The organizationId parameter. |
package hello.world;
import com.writer.api.Writer;
import com.writer.api.models.operations.*;
import com.writer.api.models.operations.DetectContentRequest;
import com.writer.api.models.operations.DetectContentResponse;
import com.writer.api.models.shared.*;
import com.writer.api.models.shared.ContentDetectorRequest;
import com.writer.api.models.shared.Security;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import static java.util.Map.entry;
public class Application {
public static void main(String[] args) {
try {
Writer sdk = Writer.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.organizationId(496531L)
.build();
DetectContentRequest req = DetectContentRequest.builder()
.contentDetectorRequest(ContentDetectorRequest.builder()
.input("<value>")
.build())
.build();
DetectContentResponse res = sdk.aiContentDetector().detect()
.request(req)
.call();
if (res.classes().isPresent()) {
// handle response
}
} catch (com.writer.api.models.errors.FailResponse e) {
// handle exception
} catch (com.writer.api.models.errors.SDKError e) {
// handle exception
} catch (Exception e) {
// handle exception
}
}
}
You can override the default server globally by passing a server index to the serverIndex
builder method when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://enterprise-api.writer.com |
None |
package hello.world;
import com.writer.api.Writer;
import com.writer.api.models.operations.*;
import com.writer.api.models.operations.GetSubscriptionDetailsResponse;
import com.writer.api.models.shared.*;
import com.writer.api.models.shared.Security;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import static java.util.Map.entry;
public class Application {
public static void main(String[] args) {
try {
Writer sdk = Writer.builder()
.serverIndex(0)
.apiKey("<YOUR_API_KEY_HERE>")
.organizationId(850421L)
.build();
GetSubscriptionDetailsResponse res = sdk.billing().getSubscriptionDetails()
.call();
if (res.subscriptionPublicResponseApi().isPresent()) {
// handle response
}
} catch (com.writer.api.models.errors.FailResponse e) {
// handle exception
} catch (com.writer.api.models.errors.SDKError e) {
// handle exception
} catch (Exception e) {
// handle exception
}
}
}
The default server can also be overridden globally by passing a URL to the serverURL
builder method when initializing the SDK client instance. For example:
package hello.world;
import com.writer.api.Writer;
import com.writer.api.models.operations.*;
import com.writer.api.models.operations.GetSubscriptionDetailsResponse;
import com.writer.api.models.shared.*;
import com.writer.api.models.shared.Security;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import static java.util.Map.entry;
public class Application {
public static void main(String[] args) {
try {
Writer sdk = Writer.builder()
.serverURL("https://enterprise-api.writer.com")
.apiKey("<YOUR_API_KEY_HERE>")
.organizationId(850421L)
.build();
GetSubscriptionDetailsResponse res = sdk.billing().getSubscriptionDetails()
.call();
if (res.subscriptionPublicResponseApi().isPresent()) {
// handle response
}
} catch (com.writer.api.models.errors.FailResponse e) {
// handle exception
} catch (com.writer.api.models.errors.SDKError e) {
// handle exception
} catch (Exception e) {
// handle exception
}
}
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Exception type.
Error Object | Status Code | Content Type |
---|---|---|
com.writer.api.models.errors.FailResponse | 400,401,403,404,500 | application/json |
models/errors/SDKError | 4xx-5xx | / |
package hello.world;
import com.writer.api.Writer;
import com.writer.api.models.operations.*;
import com.writer.api.models.operations.GetSubscriptionDetailsResponse;
import com.writer.api.models.shared.*;
import com.writer.api.models.shared.Security;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import static java.util.Map.entry;
public class Application {
public static void main(String[] args) {
try {
Writer sdk = Writer.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.organizationId(850421L)
.build();
GetSubscriptionDetailsResponse res = sdk.billing().getSubscriptionDetails()
.call();
if (res.subscriptionPublicResponseApi().isPresent()) {
// handle response
}
} catch (com.writer.api.models.errors.FailResponse e) {
// handle exception
} catch (com.writer.api.models.errors.SDKError e) {
// handle exception
} catch (Exception e) {
// handle exception
}
}
}
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
apiKey |
apiKey | API key |
To authenticate with the API the apiKey
parameter must be set when initializing the SDK client instance. For example:
package hello.world;
import com.writer.api.Writer;
import com.writer.api.models.operations.*;
import com.writer.api.models.operations.GetSubscriptionDetailsResponse;
import com.writer.api.models.shared.*;
import com.writer.api.models.shared.Security;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import static java.util.Map.entry;
public class Application {
public static void main(String[] args) {
try {
Writer sdk = Writer.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.organizationId(850421L)
.build();
GetSubscriptionDetailsResponse res = sdk.billing().getSubscriptionDetails()
.call();
if (res.subscriptionPublicResponseApi().isPresent()) {
// handle response
}
} catch (com.writer.api.models.errors.FailResponse e) {
// handle exception
} catch (com.writer.api.models.errors.SDKError e) {
// handle exception
} catch (Exception e) {
// handle exception
}
}
}