POST
/
chat
/
completions
from together import Together
import os

client = Together(
api_key=os.environ.get("TOGETHER_API_KEY"),
)

response = client.chat.completions.create(
model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What are some fun things to do in New York?"},
]
)

print(response.choices[0].message.content)
{
  "id": "<string>",
  "choices": [
    {
      "text": "<string>",
      "index": 123,
      "seed": 123,
      "finish_reason": "stop",
      "message": {
        "content": "<string>",
        "role": "assistant",
        "tool_calls": [
          {
            "index": 123,
            "id": "<string>",
            "type": "function",
            "function": {
              "name": "function_name",
              "arguments": "<string>"
            }
          }
        ],
        "function_call": {
          "arguments": "<string>",
          "name": "<string>"
        }
      },
      "logprobs": {
        "token_ids": [
          123
        ],
        "tokens": [
          "<string>"
        ],
        "token_logprobs": [
          123
        ]
      }
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  },
  "created": 123,
  "model": "<string>",
  "object": "chat.completion",
  "warnings": [
    {
      "message": "<string>"
    }
  ]
}

Authorizations

Authorization
string
header
default:default
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Response

200
application/json

200

The response is of type object.