LangDB Chat API

OpenAI-compatible chat completions and model routing.

Operations 1

POST /chat/completions Create a chat completion #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/langdb-chat-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Discovery needs no key. Ratings and market analysis are Pro.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

langdb-chat-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: LangDB AI Gateway Analytics Chat API
  description: OpenAI-compatible REST API for the LangDB AI Gateway. A single, project-scoped endpoint routes chat completions, embeddings, and image generation across 250+ models from providers such as OpenAI, Anthropic, Google, Meta, Mistral, and DeepSeek, while adding routing, guardrails, tracing, cost control, and an MCP (Model Context Protocol) gateway. Requests are authenticated with a Bearer API key and scoped to a project either by embedding the project id in the path (`/{project_id}/v1/...`) or by sending an `X-Project-Id` header. Tracing and session headers (`X-Thread-Id`, `X-Run-Id`, `X-Label`) attach observability metadata to each call.
  termsOfService: https://langdb.ai/terms
  contact:
    name: LangDB Support
    url: https://langdb.ai
    email: support@langdb.ai
  version: '1.0'
servers:
- url: https://api.us-east-1.langdb.ai/{project_id}/v1
  description: Project-scoped OpenAI-compatible base (US East 1).
  variables:
    project_id:
      default: your-langdb-project-id
      description: LangDB project id. May instead be supplied via the X-Project-Id header.
- url: https://api.us-east-1.langdb.ai
  description: Root base URL for analytics, usage, and thread management endpoints (US East 1).
security:
- bearerAuth: []
tags:
- name: Chat
  description: OpenAI-compatible chat completions and model routing.
paths:
  /chat/completions:
    post:
      operationId: createChatCompletion
      tags:
      - Chat
      summary: Create a chat completion
      description: OpenAI-compatible chat completion across any model routable by the gateway (e.g. `openai/gpt-4o`, `anthropic/claude-sonnet-4`, `gemini/gemini-2.5-pro`). Supports streaming via Server-Sent Events when `stream` is true, tool/function calling, structured outputs, and attaching MCP servers through the `mcp_servers` array. Tracing metadata can be attached via the X-Thread-Id, X-Run-Id, and X-Label headers.
      parameters:
      - $ref: '#/components/parameters/ProjectIdHeader'
      - $ref: '#/components/parameters/ThreadIdHeader'
      - $ref: '#/components/parameters/RunIdHeader'
      - $ref: '#/components/parameters/LabelHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: A chat completion, or an SSE stream when stream is true.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                type: string
                description: 'Server-Sent Events stream of ChatCompletionChunk objects terminated by `data: [DONE]`.'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  parameters:
    ProjectIdHeader:
      name: X-Project-Id
      in: header
      required: false
      description: LangDB project id. Optional when the project id is embedded in the request path.
      schema:
        type: string
    RunIdHeader:
      name: X-Run-Id
      in: header
      required: false
      description: Tracks a single workflow execution (model call or tool invocation) for observability.
      schema:
        type: string
    ThreadIdHeader:
      name: X-Thread-Id
      in: header
      required: false
      description: Groups related requests under the same conversation thread for tracing and session continuity.
      schema:
        type: string
    LabelHeader:
      name: X-Label
      in: header
      required: false
      description: Attaches a custom label/tag to the model call for categorization and tracing.
      schema:
        type: string
  responses:
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimited:
      description: Rate limit or cost limit exceeded.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string
    ChatCompletionRequest:
      type: object
      required:
      - model
      - messages
      properties:
        model:
          type: string
          description: Provider-prefixed model identifier (e.g. openai/gpt-4o, anthropic/claude-sonnet-4) or a LangDB virtual model name.
          example: openai/gpt-4o-mini
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
        temperature:
          type: number
          format: float
          default: 1
        top_p:
          type: number
          format: float
        max_tokens:
          type: integer
        stream:
          type: boolean
          default: false
          description: When true, partial deltas are streamed as Server-Sent Events.
        stop:
          oneOf:
          - type: string
          - type: array
            items:
              type: string
        tools:
          type: array
          description: Function/tool definitions in OpenAI tool-calling format.
          items:
            type: object
        tool_choice:
          oneOf:
          - type: string
          - type: object
        response_format:
          type: object
          description: Structured-output controls (e.g. a JSON object type).
        mcp_servers:
          type: array
          description: MCP servers to attach to the request, exposing their tools to the model.
          items:
            $ref: '#/components/schemas/McpServer'
        router:
          type: object
          description: LangDB routing configuration (fallbacks, load balancing, model targets).
        extra:
          type: object
          description: Additional gateway-specific routing or guardrail options.
    ChatMessage:
      type: object
      required:
      - role
      - content
      properties:
        role:
          type: string
          enum:
          - system
          - user
          - assistant
          - tool
        content:
          oneOf:
          - type: string
          - type: array
            items:
              type: object
        name:
          type: string
        tool_call_id:
          type: string
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: chat.completion
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/ChatMessage'
              finish_reason:
                type: string
        usage:
          $ref: '#/components/schemas/Usage'
    McpServer:
      type: object
      properties:
        slug:
          type: string
        name:
          type: string
        type:
          type: string
          enum:
          - sse
          - ws
          description: Transport type for the MCP server.
        server_url:
          type: string
          format: uri
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'LangDB API key (project access token) sent as `Authorization: Bearer <token>`.'