Text generation - Writer AI Studio
cURL
curl --location --request POST https://api.writer.com/v1/completions \
--header "Authorization: Bearer <token>" \
--header "Content-Type: application/json" \
--data-raw '{"model":"palmyra-x5","prompt":"Write me a short SEO article about camping gear","max_tokens":150,"temperature":0.7,"top_p":0.9,"stop":["."],"best_of":1,"random_seed":42,"stream":false}'
import os
from writerai import Writer
client = Writer(
# This is the default and can be omitted
api_key=os.environ.get("WRITER_API_KEY"),
)
completion = client.completions.create(
model="palmyra-x5",
prompt="Write me a short SEO article about camping gear",
)
print(completion.choices)
import Writer from 'writer-sdk';
const client = new Writer({
apiKey: process.env['WRITER_API_KEY'], // This is the default and can be omitted
});
async function main() {
const completion = await client.completions.create({
model: 'palmyra-x5',
prompt: 'Write me a short SEO article about camping gear',
});
console.log(completion.choices);
}
main();
200
{
"choices": [\
{\
"text": "Sure! Here's a search engine optimized article about...",\
"log_probs": null\
}\
],
"model": "palmyra-x5"
}
Authorizations
Authorization
string
header
required
Bearer authentication header of the form Bearer <token>, where <token> is your Writer API key.
Body
application/json
model
string
required
The ID of the model to use for generating text. This can be a Palmyra model such as palmyra-x5 or palmyra-x4, or the ID of an external model configured for your organization.
prompt
string
required
The input text that the model will process to generate a response.
max_tokens
integer
The maximum number of tokens that the model can generate in the response.
temperature
number
Controls the randomness of the model's outputs. Higher values lead to more random outputs, while lower values make the model more deterministic.
top_p
number
Used to control the nucleus sampling, where only the most probable tokens with a cumulative probability of top_p are considered for sampling.
stop
string[]
Specifies stopping conditions for the model's output generation. This can be an array of strings or a single string that the model will look for as a signal to stop generating further tokens. best_of
integer
Specifies the number of completions to generate and return the best one. random_seed
integer
A seed used to initialize the random number generator for the model. stream
boolean
Determines whether the model's output should be streamed.
Response
200
application/json
Successful response
choices
object[]
required
A list of choices generated by the model, each containing the text of the completion and associated metadata such as log probabilities.
model
string
The identifier of the model that was used to generate the responses in the 'choices' array.