For the complete documentation index, see llms.txt. This page is also available as Markdown.

Chat Completions

Create a model response for the given chat conversation.


Endpoint

POST https://api.tensorx.ai/v1/chat/completions

Authentication

Authorization: Bearer YOUR_API_KEY

API key is required for all requests. Get your key from your TensorX dashboard.


Request Body

Parameter
Type
Required
Default
Description

model

string

Yes

-

Model ID (e.g., deepseek/deepseek-chat-v3.1)

messages

array

Yes

-

Array of message objects

max_tokens

integer

No

Model default

Maximum tokens to generate

temperature

number

No

1.0

Sampling temperature (0-2)

top_p

number

No

1.0

Nucleus sampling (0-1)

top_k

integer

No

-

Top-k sampling

stream

boolean

No

false

Stream partial responses

stop

string/array

No

-

Stop sequences (up to 4)

presence_penalty

number

No

0

Presence penalty (-2 to 2)

frequency_penalty

number

No

0

Frequency penalty (-2 to 2)

response_format

object

No

-

Force output format

tools

array

No

-

Function calling tools

Message Object

Field
Type
Required
Description

role

string

Yes

system, user, or assistant

content

string

Yes

Message content


Example Request

cURL

Python

JavaScript


Response

Success (200)

Response Fields

Field
Type
Description

id

string

Unique response identifier

object

string

Always chat.completion

created

integer

Unix timestamp

model

string

Model used for generation

choices

array

Generated completions

choices[].message

object

Assistant's response message

choices[].finish_reason

string

Why generation stopped (stop, length, tool_calls)

usage

object

Token usage statistics


Streaming

Enable streaming for real-time responses:

Streaming responses are sent as Server-Sent Events (SSE):

Python Streaming


JSON Mode

Force the model to output valid JSON:

When using JSON mode, include "JSON" in your prompt for best results.


Reasoning

Several models expose a separate reasoning (thinking) step, returned in reasoning_content on the message. Controls differ by model family. See Reasoning for the full per-model reference.


Function Calling

Use tools for function calling:


Error Responses

401 Unauthorized

402 Insufficient Credits

429 Rate Limited


Best Practices

  1. Use streaming for long responses to improve user experience

  2. Set appropriate max_tokens to control costs and response length

  3. Use lower temperature (0.1-0.3) for factual tasks, higher (0.7-1.0) for creative tasks

  4. Include system prompts to guide model behavior

  5. Handle errors gracefully with retry logic for transient failures


See Also

  • Models - Available models

  • API Examples - More code examples

  • Pricing - Model pricing

Last updated

Was this helpful?