# Docs for v2 can be found by changing the above selector ^
from together import Together
import os
client = Together(
api_key=os.environ.get("TOGETHER_API_KEY"),
)
response = client.completions.create(
model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
prompt="The largest city in France is",
max_tokens=1
)
print(response.choices[0].text){
"id": "<string>",
"choices": [
{
"text": "The capital of France is Paris. It's located in the north-central part of the country and is one of the most populous and visited cities in the world, known for its iconic landmarks like the Eiffel Tower, Louvre Museum, Notre-Dame Cathedral, and more. Paris is also the capital of the Île-de-France region and is a major global center for art, fashion, gastronomy, and culture.",
"seed": 123,
"finish_reason": "stop",
"logprobs": {
"token_ids": [
123
],
"tokens": [
"<string>"
],
"token_logprobs": [
123
]
}
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
},
"created": 123,
"model": "<string>",
"object": "text.completion",
"prompt": [
{
"text": "<s>[INST] What is the capital of France? [/INST]",
"logprobs": {
"token_ids": [
123
],
"tokens": [
"<string>"
],
"token_logprobs": [
123
]
}
}
]
}Query a language, code, or image model.
# Docs for v2 can be found by changing the above selector ^
from together import Together
import os
client = Together(
api_key=os.environ.get("TOGETHER_API_KEY"),
)
response = client.completions.create(
model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
prompt="The largest city in France is",
max_tokens=1
)
print(response.choices[0].text){
"id": "<string>",
"choices": [
{
"text": "The capital of France is Paris. It's located in the north-central part of the country and is one of the most populous and visited cities in the world, known for its iconic landmarks like the Eiffel Tower, Louvre Museum, Notre-Dame Cathedral, and more. Paris is also the capital of the Île-de-France region and is a major global center for art, fashion, gastronomy, and culture.",
"seed": 123,
"finish_reason": "stop",
"logprobs": {
"token_ids": [
123
],
"tokens": [
"<string>"
],
"token_logprobs": [
123
]
}
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
},
"created": 123,
"model": "<string>",
"object": "text.completion",
"prompt": [
{
"text": "<s>[INST] What is the capital of France? [/INST]",
"logprobs": {
"token_ids": [
123
],
"tokens": [
"<string>"
],
"token_logprobs": [
123
]
}
}
]
}Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
A string providing context for the model to complete.
"<s>[INST] What is the capital of France? [/INST]"
The name of the model to query.
See all of Together AI's chat models
meta-llama/Llama-2-70b-hf, mistralai/Mistral-7B-v0.1, mistralai/Mixtral-8x7B-v0.1, Meta-Llama/Llama-Guard-7b "mistralai/Mixtral-8x7B-Instruct-v0.1"
The maximum number of tokens to generate.
A list of string sequences that will truncate (stop) inference text output. For example, "" will stop generation as soon as the model generates the given token.
A decimal number from 0-1 that determines the degree of randomness in the response. A temperature less than 1 favors more correctness and is appropriate for question answering or summarization. A value closer to 1 introduces more randomness in the output.
A percentage (also called the nucleus parameter) that's used to dynamically adjust the number of choices for each predicted token based on the cumulative probabilities. It specifies a probability threshold below which all less likely tokens are filtered out. This technique helps maintain diversity and generate more fluent and natural-sounding text.
An integer that's used to limit the number of choices for the next predicted word or token. It specifies the maximum number of tokens to consider at each step, based on their probability of occurrence. This technique helps to speed up the generation process and can improve the quality of the generated text by focusing on the most likely options.
A number that controls the diversity of generated text by reducing the likelihood of repeated sequences. Higher values decrease repetition.
If true, stream tokens as Server-Sent Events as the model generates them instead of waiting for the full model response. The stream terminates with data: [DONE]. If false, return a single JSON object containing the results.
An integer between 0 and 20 of the top k tokens to return log probabilities for at each generation step, instead of just the sampled token. Log probabilities help assess model confidence in token predictions.
0 <= x <= 20If true, the response will contain the prompt. Can be used with logprobs to return prompt logprobs.
The number of completions to generate for each prompt.
1 <= x <= 128A number between 0 and 1 that can be used as an alternative to top-p and top-k.
A number between -2.0 and 2.0 where a positive value increases the likelihood of a model talking about new topics.
A number between -2.0 and 2.0 where a positive value decreases the likelihood of repeating tokens that have already been mentioned.
Seed value for reproducibility.
42
200
Show child attributes
"The capital of France is Paris. It's located in the north-central part of the country and is one of the most populous and visited cities in the world, known for its iconic landmarks like the Eiffel Tower, Louvre Museum, Notre-Dame Cathedral, and more. Paris is also the capital of the Île-de-France region and is a major global center for art, fashion, gastronomy, and culture."
stop, eos, length, tool_calls, function_call text.completion Show child attributes
"<s>[INST] What is the capital of France? [/INST]"
Was this page helpful?