API Reference

API Endpoints for LangDB

Create chat completion

post
Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Header parameters
X-Project-IdstringRequired

LangDB project ID

Body
modelstringRequired

ID of the model to use. This can be either a specific model ID or a virtual model identifier.

Example: gpt-4o
temperaturenumber · max: 2Optional

Sampling temperature.

Example: 0.8
top_pnumber · max: 1Optional

Nucleus sampling probability.

max_tokensinteger · min: 1Optional

The maximum number of tokens that can be generated in the chat completion.

ninteger · min: 1Optional

How many chat completion choices to generate for each input message.

Default: 1
stopone ofOptional

Up to 4 sequences where the API will stop generating further tokens.

stringOptional
or
string[]Optional
presence_penaltynumber · min: -2 · max: 2Optional

Penalize new tokens based on whether they appear in the text so far.

frequency_penaltynumber · min: -2 · max: 2Optional

Penalize new tokens based on their existing frequency in the text so far.

logprobsbooleanOptional

Whether to return log probabilities of the output tokens.

top_logprobsinteger · min: 1 · max: 20Optional

The number of most likely tokens to return at each position, for which the log probabilities are returned. Requires logprobs=true.

seedintegerOptional

If specified, the backend will make a best effort to return deterministic results.

response_formatone ofOptional

Format for the model's response.

string · enumOptionalPossible values:
or
tool_choiceone ofOptional

Controls which (if any) tool is called by the model. none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools.

string · enumOptionalPossible values:
or
or
parallel_tool_callsbooleanOptional

Whether to enable parallel function calling during tool use.

Default: true
streambooleanOptional

Whether to stream back partial progress.

Default: false
userstringOptionalDeprecated

Deprecated. This field is being replaced by safety_identifier and prompt_cache_key. Use prompt_cache_key to maintain caching optimizations. A stable identifier for your end-users was previously used to boost cache hit rates by better bucketing similar requests and to help detect and prevent abuse.

safety_identifierstringOptional

Stable identifier for your end-users, used to help detect and prevent abuse. Prefer this over user. For caching optimization, combine with prompt_cache_key.

prompt_cache_keystringOptional

Used to cache responses for similar requests to optimize cache hit rates. LangDB supports prompt caching; see https://docs.langdb.ai/features/prompt-caching. Can be used instead of the user field for cache bucketing.

Responses
200

OK

application/json
post
/v1/chat/completions
200

OK

Create embeddings

post

Creates an embedding vector representing the input text or token arrays.

Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Body
modelstringRequired

ID of the model to use for generating embeddings.

Example: text-embedding-ada-002
inputone ofRequired
stringOptional

The text to embed.

or
string[]Optional

Array of text strings to embed.

encoding_formatstring · enumOptional

The format to return the embeddings in.

Default: floatPossible values:
dimensionsinteger · min: 1 · max: 1536Optional

The number of dimensions the resulting embeddings should have.

Example: 1536
Responses
200

Successful response with embeddings

application/json
post
/v1/embeddings
200

Successful response with embeddings

Retrieve a list of threads

post
Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Header parameters
X-Project-IdstringRequired

LangDB project ID

Body
limitinteger · min: 1RequiredExample: 10
offsetintegerRequiredExample: 100
Responses
200

A list of threads with pagination info

application/json
post
/threads
200

A list of threads with pagination info

Retrieve messages for a specific thread

get
Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Path parameters
thread_idstring · uuidRequired

The ID of the thread to retrieve messages from

Header parameters
X-Project-IdstringRequired

LangDB project ID

Responses
200

A list of messages for the given thread

application/json
get
/threads/{thread_id}/messages
200

A list of messages for the given thread

Retrieve the total cost for a specific thread

get
Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Path parameters
thread_idstring · uuidRequired

The ID of the thread for which to retrieve cost information

Header parameters
X-Project-IdstringRequired

LangDB project ID

Responses
200

The total cost and token usage for the specified thread

application/json
get
/threads/{thread_id}/cost
200

The total cost and token usage for the specified thread

Fetch analytics data

post
Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Header parameters
X-Project-IdstringRequired

LangDB project ID

Body
start_time_usinteger · int64OptionalDeprecated

Start time in microseconds.

Example: 1693062345678
end_time_usinteger · int64OptionalDeprecated

End time in microseconds.

Example: 1693082345678
periodstring · enumOptional

Time period for filtering data. If provided, start_time and end_time will be ignored.

Example: last_monthPossible values:
Responses
200

Successful response

application/json
post
/analytics
200

Successful response

Fetch analytics summary

post
Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Header parameters
X-Project-IdstringRequired

LangDB project ID

Body
start_time_usinteger · int64OptionalDeprecatedExample: 1693062345678
end_time_usinteger · int64OptionalDeprecatedExample: 1693082345678
periodstring · enumOptional

Time period for filtering data. If provided, start_time and end_time will be ignored.

Example: last_monthPossible values:
groupBystring[]RequiredExample: ["provider"]
Responses
200

Successful response

application/json
post
/analytics/summary
200

Successful response

Get total usage

post
Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Header parameters
X-Project-IdstringRequired

LangDB project ID

Body
start_time_usinteger · int64OptionalDeprecatedExample: 1693062345678
end_time_usinteger · int64OptionalDeprecated

End time in microseconds.

Example: 1693082345678
periodstring · enumOptional

Time period for filtering data. If provided, start_time and end_time will be ignored.

Example: last_monthPossible values:
Responses
200

OK

application/json
post
/usage/total
200

OK

Get usage by model

post
Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Header parameters
X-Project-IdstringRequired

LangDB project ID

Body
start_time_usinteger · int64OptionalExample: 1693062345678
end_time_usinteger · int64Optional
min_unitstring · enumOptional

The granularity of the returned usage data.

Example: hourPossible values:
Responses
200

Successful response

application/json
post
/usage/models
200

Successful response

Retrieve pricing information

get

Returns the pricing details for LangDB services.

Responses
200

Successful retrieval of pricing information

application/json
get
/pricing
200

Successful retrieval of pricing information

List models

get
Responses
200

OK

application/json
get
/models
200

OK

Create a new model

post

Register and configure a new LLM under your LangDB project

Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Header parameters
X-Admin-KeystringRequired

LangDB Admin Key

Body
model_namestringRequiredExample: my-model
descriptionstringRequiredExample: A custom completions model for text and image inputs
provider_info_idstring · uuidRequiredExample: e2e9129b-6661-4eeb-80a2-0c86964974c9
project_idstringRequiredExample: 55f4a12b-74c8-4294-8e4b-537f13fc3861
publicbooleanOptionalExample: false
request_response_mappingstringOptionalExample: openai-compatible
model_typestringRequiredExample: completions
input_token_pricenumber · float | nullableOptionalExample: 0.00001
output_token_pricenumber · float | nullableOptionalExample: 0.00003
context_sizeinteger | nullableOptionalExample: 128000
capabilitiesstring[]OptionalExample: ["tools"]
input_typesstring[]OptionalExample: ["text","image"]
output_typesstring[]OptionalExample: ["text","image"]
tagsstring[]Optional
mp_pricenumber · float | nullableOptional
owner_namestringRequiredExample: openai
priorityintegerRequiredExample: 0
model_name_in_providerstringOptionalExample: my-model-v1.2
parametersobjectOptional

Additional configuration parameters

Example: {"top_k":{"default":0,"description":"Limits the token sampling to only the top K tokens.","min":0,"required":false,"step":1,"type":"int"},"top_p":{"default":1,"description":"Nucleus sampling alternative.","max":1,"min":0,"required":false,"step":0.05,"type":"float"}}
Responses
200

Created

application/json
post
/admin/models
200

Created

Set custom prices for imported models

post

Set custom pricing for models imported from providers like Bedrock, Azure, Vertex that do not have built-in pricing

Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Path parameters
project_idstring · uuidRequired

UUID of the project

Example: 25a0b7d9-86cf-448d-8395-66e9073d876f
Body

Request body for setting custom prices on imported models

Responses
200

Custom prices set successfully

application/json
post
/projects/{project_id}/custom_prices
200

Custom prices set successfully

Last updated

Was this helpful?