Skip to main content
This guide helps you make your first API calls to the Writer API. You’ll create an API key in AI Studio and begin making API calls to generate text using the chat completion endpoint.

Get an API key

Before you can make API calls, you need to create an API key in AI Studio.
1

Navigate to API Keys

From the AI Studio home page, open Admin settings in the left sidebar, then select API Keys.
2

Create an API agent

Click the Create API agent button in the top right corner of the page.
3

Configure the agent

Select the title field for the API agent and give it a name. Add a short description so you can keep track of what the agent is for.
4

Get your API key

On the Manage keys tab, each key is listed by name (the default is Production). The first time a key is created, copy the full value with Copy and store it in a secure place. You can’t view or reveal the full key again after that.
Copy and store the key as soon as it’s shown. After you leave this step, the full value is no longer available.
You can generate another key with the same capabilities from Generate a new key on the agent page.
Store the API key in a secure location, such as a .env file.
You can now make calls to the Writer API using this API key as the Bearer token in the header:
Authorization: Bearer <api-key>
Learn more about managing API keys in the API keys guide.

Make your first API call

Below is an example of an API call to the chat completion endpoint. It completes a single-turn chat completion, where the user provides a message and the AI assistant generates a response. The request is non-streaming and waits until the response is complete before returning.
curl --location 'https://api.writer.com/v1/chat' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-api-key>' \
--data '{
    "model": "palmyra-x5",
    "messages": [
        {
            "role": "user",
            "content": "Write a one sentence product description for a cozy, stylish sweater suitable for both casual and formal occasions"
        }
    ]
}'
The response is a JSON object with a choices array. The message.content field of the first choice contains the generated text. The message.role field indicates that the message is an AI assistant message.
{
  "id": "78766762-bd30-4a42-bb2b-e0b35c608217",
  "object": "chat.completion",
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {
        "content": "This versatile, cozy sweater blends warmth and elegance with its soft knit and refined design, making it perfect for both casual days and formal evenings.",
        "role": "assistant",
        "tool_calls": null,
        "graph_data": {
          "sources": null,
          "status": null,
          "subqueries": null
        },
        "llm_data": null,
        "image_data": null,
        "refusal": null
      },
      "logprobs": null
    }
  ],
  "created": 1740711212,
  "model": "palmyra-x5",
  "usage": {
    "prompt_tokens": 50,
    "total_tokens": 79,
    "completion_tokens": 29,
    "prompt_token_details": null,
    "completion_tokens_details": null
  },
  "system_fingerprint": "v1",
  "service_tier": null
}
In a streaming response, the structure of the response is similar. However, the content of the streamed response is returned in a choices[0].delta.content field, rather than the choices[0].message.content field. Learn more about streaming responses in the chat completion guide.
You can customize your request to the chat completion endpoint by adding or updating parameters to the request body. Learn more about the different parameters in the chat completion endpoint API reference.

Next steps

Now that you’ve made your first API call, learn how to use the Writer SDKs to make calls to the Writer API in your applications. Or, learn more about building with the chat completion endpoint: