go get github.com/writerai/writer-client-sdk-go
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 main
import (
"context"
writerclientsdkgo "github.com/writerai/writer-client-sdk-go"
"github.com/writerai/writer-client-sdk-go/pkg/models/shared"
"log"
)
func main() {
s := writerclientsdkgo.New(
writerclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
writerclientsdkgo.WithOrganizationID(850421),
)
ctx := context.Background()
res, err := s.Billing.GetSubscriptionDetails(ctx)
if err != nil {
log.Fatal(err)
}
if res.SubscriptionPublicResponseAPI != nil {
// handle response
}
}
- 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 99895
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 | int64 | ✔️ | The OrganizationID parameter. |
package main
import (
"context"
writerclientsdkgo "github.com/writerai/writer-client-sdk-go"
"github.com/writerai/writer-client-sdk-go/pkg/models/shared"
"log"
)
func main() {
s := writerclientsdkgo.New(
writerclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
writerclientsdkgo.WithOrganizationID(496531),
)
contentDetectorRequest := shared.ContentDetectorRequest{
Input: "<value>",
}
var organizationID *int64 = writerclientsdkgo.Int64(592237)
ctx := context.Background()
res, err := s.AIContentDetector.Detect(ctx, contentDetectorRequest, organizationID)
if err != nil {
log.Fatal(err)
}
if res.Classes != nil {
// handle response
}
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.FailResponse | 400,401,403,404,500 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
package main
import (
"context"
"errors"
writerclientsdkgo "github.com/writerai/writer-client-sdk-go"
"github.com/writerai/writer-client-sdk-go/pkg/models/sdkerrors"
"github.com/writerai/writer-client-sdk-go/pkg/models/shared"
"log"
)
func main() {
s := writerclientsdkgo.New(
writerclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
writerclientsdkgo.WithOrganizationID(850421),
)
ctx := context.Background()
res, err := s.Billing.GetSubscriptionDetails(ctx)
if err != nil {
var e *sdkerrors.FailResponse
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
var e *sdkerrors.SDKError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
}
}
You can override the default server globally using the WithServerIndex
option 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 main
import (
"context"
writerclientsdkgo "github.com/writerai/writer-client-sdk-go"
"github.com/writerai/writer-client-sdk-go/pkg/models/shared"
"log"
)
func main() {
s := writerclientsdkgo.New(
writerclientsdkgo.WithServerIndex(0),
writerclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
writerclientsdkgo.WithOrganizationID(850421),
)
ctx := context.Background()
res, err := s.Billing.GetSubscriptionDetails(ctx)
if err != nil {
log.Fatal(err)
}
if res.SubscriptionPublicResponseAPI != nil {
// handle response
}
}
The default server can also be overridden globally using the WithServerURL
option when initializing the SDK client instance. For example:
package main
import (
"context"
writerclientsdkgo "github.com/writerai/writer-client-sdk-go"
"github.com/writerai/writer-client-sdk-go/pkg/models/shared"
"log"
)
func main() {
s := writerclientsdkgo.New(
writerclientsdkgo.WithServerURL("https://enterprise-api.writer.com"),
writerclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
writerclientsdkgo.WithOrganizationID(850421),
)
ctx := context.Background()
res, err := s.Billing.GetSubscriptionDetails(ctx)
if err != nil {
log.Fatal(err)
}
if res.SubscriptionPublicResponseAPI != nil {
// handle response
}
}
The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
The built-in net/http
client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.
import (
"net/http"
"time"
"github.com/myorg/your-go-sdk"
)
var (
httpClient = &http.Client{Timeout: 30 * time.Second}
sdkClient = sdk.New(sdk.WithClient(httpClient))
)
This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
APIKey |
apiKey | API key |
You can configure it using the WithSecurity
option when initializing the SDK client instance. For example:
package main
import (
"context"
writerclientsdkgo "github.com/writerai/writer-client-sdk-go"
"log"
)
func main() {
s := writerclientsdkgo.New(
writerclientsdkgo.WithSecurity("<YOUR_API_KEY_HERE>"),
writerclientsdkgo.WithOrganizationID(850421),
)
ctx := context.Background()
res, err := s.Billing.GetSubscriptionDetails(ctx)
if err != nil {
log.Fatal(err)
}
if res.SubscriptionPublicResponseAPI != nil {
// handle response
}
}