Native API (Direct Routes)

Base URL: https://api.langmart.ai/native/{provider}

The Native API lets you send requests in each provider's native format through LangMart. Zero translation, full provider feature access, with auth, PII protection, billing, and logging.

What is the Native API?

LangMart normally translates all requests to and from the OpenAI format. This is the translation mode, available at /v1/* endpoints. It works great when you want a single, unified API across all providers.

The Native API (/native/{provider}/*) is an alternative mode where your requests pass through in the provider's native format. LangMart only applies its value-add layer:

  • Authentication -- swap your LangMart key for the provider's key
  • PII Protection -- detect and redact sensitive data
  • Rate Limiting -- enforce usage quotas
  • Request Logging -- full audit trail
  • Billing -- per-token usage tracking

No format translation, no field mapping, no feature loss.

When to Use Native API vs Translation Mode

Feature Translation Mode (/v1/*) Native Mode (/native/*)
Request format Always OpenAI Provider native
Response format Always OpenAI Provider native
SDK compatibility Any OpenAI-compatible SDK Provider's own SDK
Provider features Limited to OpenAI schema Full provider features
Model naming provider/model prefix Exact provider model name
Use case Simple, unified access Enterprise, SDK migration

Use Translation Mode when you want one SDK/format for all providers.

Use Native Mode when you have existing code using provider SDKs and want to add LangMart's governance layer without rewriting.

Base URL Pattern

https://api.langmart.ai/native/{provider}

The {provider} maps to the provider key in LangMart. After the base URL, append the provider's normal API path. For example, Anthropic's messages endpoint is /v1/messages, so the full URL becomes:

https://api.langmart.ai/native/anthropic/v1/messages

Supported Providers

Provider Key Example URL
Anthropic anthropic /native/anthropic/v1/messages
Google Gemini google /native/google/v1beta/models/{model}:generateContent
OpenAI openai /native/openai/v1/chat/completions
Groq groq /native/groq/openai/v1/chat/completions
Mistral mistral /native/mistral/v1/chat/completions
DeepSeek deepseek /native/deepseek/v1/chat/completions
xAI (Grok) xai /native/xai/v1/chat/completions
Together AI together /native/together/v1/chat/completions
Fireworks fireworks /native/fireworks/v1/chat/completions
Perplexity perplexity /native/perplexity/v1/chat/completions
OpenRouter openrouter /native/openrouter/v1/chat/completions
Azure OpenAI azure-openai /native/azure-openai/...
Ollama ollama /native/ollama/v1/chat/completions

Authentication

Authentication works the same way as translation mode. Include your LangMart API key in the Authorization header:

Authorization: Bearer YOUR_LANGMART_API_KEY

LangMart swaps your key for the provider's key automatically. You never need to manage individual provider keys.

Provider-specific headers pass through unchanged:

Provider Headers Forwarded
Anthropic anthropic-version, anthropic-beta
Google x-goog-api-client
OpenAI openai-organization, openai-project
Azure OpenAI api-version (query param)

Quick Start Examples

Anthropic (Python)

import anthropic

client = anthropic.Anthropic(
    api_key="YOUR_LANGMART_API_KEY",
    base_url="https://api.langmart.ai/native/anthropic"
)

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)
print(message.content[0].text)

Anthropic (curl)

curl -X POST https://api.langmart.ai/native/anthropic/v1/messages \
  -H "Authorization: Bearer YOUR_LANGMART_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

Google Gemini (Python)

import google.generativeai as genai

genai.configure(
    api_key="YOUR_LANGMART_API_KEY",
    transport="rest",
    client_options={
        "api_endpoint": "api.langmart.ai/native/google"
    }
)

model = genai.GenerativeModel("gemini-2.0-flash")
response = model.generate_content("Hello!")
print(response.text)

OpenAI (Python)

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_LANGMART_API_KEY",
    base_url="https://api.langmart.ai/native/openai/v1"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

Note: For OpenAI, native mode works the same as translation mode but uses gpt-4o directly without the openai/ prefix.

Groq (curl)

curl -X POST https://api.langmart.ai/native/groq/openai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_LANGMART_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

Streaming

Streaming works exactly like it does with each provider's native API. LangMart proxies the SSE stream without modification.

Provider How to Enable Stream Format
Anthropic stream=True in SDK SSE with event: message_start, content_block_delta, etc.
OpenAI / Groq / Mistral stream=True in SDK SSE with data: {...} and data: [DONE]
Google Gemini :streamGenerateContent endpoint SSE with JSON chunks

Streaming Example (Anthropic)

import anthropic

client = anthropic.Anthropic(
    api_key="YOUR_LANGMART_API_KEY",
    base_url="https://api.langmart.ai/native/anthropic"
)

with client.messages.stream(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku"}]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Provider Features (Full Access)

Because there is no translation layer, every provider-specific feature works out of the box:

Provider Features Available
Anthropic Extended thinking, prompt caching, tool use, anthropic-beta features
Google Gemini Grounding, safety settings, function calling, system instructions
OpenAI Structured outputs, function calling, vision, JSON mode
Groq Ultra-fast inference, Groq-specific timing metadata
Mistral Function calling, JSON mode, code generation

Model Resolution

In native mode, use the exact model name as the provider's API expects it. Do not add a provider/ prefix:

Mode Model Name
Translation (/v1/*) anthropic/claude-3-5-sonnet-20241022
Native (/native/anthropic/*) claude-3-5-sonnet-20241022
Translation (/v1/*) groq/llama-3.3-70b-versatile
Native (/native/groq/*) llama-3.3-70b-versatile

The model must be discovered and active in your LangMart account. If the model is not found, you'll receive a 404 error in the provider's native error format.

Billing

Billing works identically to translation mode. LangMart extracts token usage from the provider's response and bills per token according to your account's pricing.

All native API requests appear in the same dashboard, request logs, and analytics views as translation mode requests.

Connection Selection

By default, LangMart selects the best available connection for the specified provider based on your account and organization settings.

To target a specific connection, include the X-LangMart-Connection header:

curl -X POST https://api.langmart.ai/native/anthropic/v1/messages \
  -H "Authorization: Bearer YOUR_LANGMART_API_KEY" \
  -H "X-LangMart-Connection: YOUR_CONNECTION_ID" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-3-5-sonnet-20241022", "max_tokens": 100, "messages": [{"role": "user", "content": "Hi"}]}'

Discovery Endpoint

You can list the native providers available for your account:

curl https://api.langmart.ai/native \
  -H "Authorization: Bearer YOUR_LANGMART_API_KEY"

Response:

{
  "success": true,
  "providers": [
    {"key": "anthropic", "name": "Anthropic", "baseUrl": "/native/anthropic"},
    {"key": "google", "name": "Google AI", "baseUrl": "/native/google"},
    {"key": "openai", "name": "OpenAI", "baseUrl": "/native/openai"}
  ]
}

Error Handling

Errors from the provider are returned in the provider's native error format. LangMart does not translate error responses.

Anthropic Error Format

{
  "type": "error",
  "error": {
    "type": "not_found_error",
    "message": "Model 'claude-xyz' not found."
  }
}

OpenAI Error Format

{
  "error": {
    "message": "Model 'gpt-xyz' not found.",
    "type": "invalid_request_error",
    "param": null,
    "code": "model_not_found"
  }
}

Google Error Format

{
  "error": {
    "code": 404,
    "message": "Model not found.",
    "status": "NOT_FOUND"
  }
}

LangMart-Specific Errors

These errors are also returned in the provider's native format:

Error Status Description
Model not found 404 Model not discovered or inactive in your account
Insufficient credits 402 Credit balance below minimum threshold
Connection unavailable 503 No active connection for this provider
Authentication required 401 Missing or invalid LangMart API key

Migrating from Direct Provider Access

Switching from direct provider access to LangMart's Native API takes three steps:

Before (Direct to Anthropic)

client = anthropic.Anthropic(
    api_key="sk-ant-your-anthropic-key"
)

After (Through LangMart)

client = anthropic.Anthropic(
    api_key="YOUR_LANGMART_API_KEY",
    base_url="https://api.langmart.ai/native/anthropic"
)

That's it. No other code changes needed. Your existing SDK calls, streaming, tool use, and all other features continue to work identically.