This guide explains the Chat completion endpoint which can be thought of as having a conversation with our LLM.

This endpoint facilitates engaging and dynamic conversations between a user and an AI-assisted chat model. It’s designed to handle both multi-turn and single-turn interactions effectively. This guide will walk you through making requests to the endpoint and understanding its responses.

Your API key can be generated using these steps.

Endpoint overview

This endpoint is designed for generating chat responses based on a conversation history provided in the request. It supports complex, contextual interactions that can simulate a conversational partner. The responses will contain the following variables:

  1. id: A unique identifier for the conversation.
  2. choices: Contains objects describing the completion, including the role (user or assistant) and content.
  3. finish_reason: Indicates why the response was concluded (stop, length, function_call, content_filter, null).

Usage example

Here’s how you can use the endpoint in a practical scenario:

1

Create a request

Use your preferred HTTP client to send a POST request to api.writer.com/v1/chat with the JSON payload.

2

Handle the response

For the response parse the JSON to access the generated text.

3

Error handling

Ensure to handle potential errors such as timeouts or model errors gracefully.

4

Rate limiting

Be mindful of any rate limits that might apply to avoid service disruptions.

Best practices

This guide should equip you with the knowledge to integrate and utilize the Chat completion endpoint effectively, enhancing your applications with robust, conversational AI capabilities.