LLM API
TTAPI LLM API, Cheap and stable chatgpt
ChatGPT - Create chat completion
POST
https://api.ttapi.io/v1/chat/completions
Creates a model response for the given chat conversation.
Headers
Name | Type | Description |
---|---|---|
TT-API-KEY* | String | Your API Key in TT API used for request authorization |
Request Body
Name | Type | Required | Description |
---|---|---|---|
messages | array | true | A list of messages comprising the conversation so far. Example code. |
model | string | true | ID of the model to use. See the model endpoint compatibility table for details on which models work with the Chat API. |
others | ... | false | More refer to... (opens in a new tab) |
Example Request
import requests
endpoint = "https://api.ttapi.io/v1/chat/completions"
headers = {
"TT-API-KEY": your_key
}
data = {
"messages":[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"model": "gpt-4o"
}
response = requests.post(endpoint, headers=headers, json=data)
print(response.status_code)
print(response.json())
Example Response
{
"id": "chatcmpl-83jZ61GDHtdlsFUzXDbpGeoU193Mj",
"object": "chat.completion",
"created": 1695900828,
"model": "gpt-3.5-turbo",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I assist you today?"
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 19,
"completion_tokens": 9,
"total_tokens": 28
}
}
Claude - Create a Message
POST
https://api.ttapi.io/v1/messages
Create a Message.
Headers
Name | Type | Description |
---|---|---|
TT-API-KEY* | String | Your API Key in TT API used for request authorization |
Request Body
Name | Type | Required | Description |
---|---|---|---|
messages | array | true | Example with a single user message. Example code. |
model | string | true | See models for additional details and options. |
max_tokens | integer | true | The maximum number of tokens to generate before stopping. |
others | ... | false | More refer to... (opens in a new tab) |
Example Request
import requests
endpoint = "https://api.ttapi.io/v1/messages"
headers = {
"TT-API-KEY": your_key
}
data = {
"messages":[
{"role": "user", "content": "Hello!"}
],
"model": "claude-3-5-sonnet-20240620",
"max_tokens": 1024
}
response = requests.post(endpoint, headers=headers, json=data)
print(response.status_code)
print(response.json())
Example Response
{
"content": [
{
"text": "Hi! My name is Claude.",
"type": "text"
}
],
"id": "msg_013Zva2CMHLNnXjNJJKqJ2EF",
"model": "claude-3-5-sonnet-20240620",
"role": "assistant",
"stop_reason": "end_turn",
"stop_sequence": null,
"type": "message",
"usage": {
"input_tokens": 10,
"output_tokens": 25
}
}
GPT - Example Message
[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
Claude - Example Message
[
{"role": "user", "content": "Hello there."},
{"role": "assistant", "content": "Hi, I'm Claude. How can I help you?"},
{"role": "user", "content": "Can you explain LLMs in plain English?"},
]