> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Make your first gateway-proxied LLM call.

<Note>
  **Private beta:** The LLM Gateway is in private [beta](/langsmith/release-stages). Sign up for [the waitlist](https://www.langchain.com/langsmith-llm-gateway-waitlist) to get access.
</Note>

## Prerequisites

Before you start, confirm that:

* Your [Organization admin](/langsmith/rbac#organization-admin) has enabled the LLM Gateway and added provider API keys to workspace secrets. To set this up, refer to [Admin setup](/langsmith/llm-gateway-admin-setup).
* You have a workspace-scoped [LangSmith API key](/langsmith/create-account-api-key) attached to a role with `gateway:invoke` and `workspaces:read` [permissions](/langsmith/organization-workspace-operations). Ask your org admin if you're unsure.

## 1. Set environment variables

Set the following in your terminal (or add them to your `~/.zshrc` to persist across sessions):

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export BASE_URL="https://gateway.smith.langchain.com"

export ANTHROPIC_BASE_URL="$BASE_URL/anthropic"
export OPENAI_BASE_URL="$BASE_URL/openai/v1"
export GOOGLE_GEMINI_BASE_URL="$BASE_URL/gemini"

export LANGSMITH_API_KEY="lsv2_..._....cbed3e"

export ANTHROPIC_API_KEY="$LANGSMITH_API_KEY"
export OPENAI_API_KEY="$LANGSMITH_API_KEY"
export GEMINI_API_KEY="$LANGSMITH_API_KEY"
export GOOGLE_API_KEY="$LANGSMITH_API_KEY"
```

This points all provider SDKs at the LangSmith Gateway and uses your LangSmith API key for authentication. The gateway resolves actual provider keys from your workspace's Provider Secrets—you never need local copies of provider API keys.

<Note>
  If your LangSmith account is on the EU or APAC instance, use the corresponding regional gateway:

  * EU: `https://eu.gateway.smith.langchain.com`
  * APAC: `https://apac.gateway.smith.langchain.com`

  These gateways are deployed in LangChain's regional production environments. There is no automatic region routing.
</Note>

## 2. Make a call

<CodeGroup>
  ```bash curl theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  curl https://gateway.smith.langchain.com/openai/v1/chat/completions \
      -H "Authorization: Bearer $LANGSMITH_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"ping"}]}'
  ```

  ```python OpenAI SDK theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  import os

  from openai import OpenAI

  client = OpenAI(
      base_url=os.environ["OPENAI_BASE_URL"],
      api_key=os.environ["LANGSMITH_API_KEY"],
  )
  response = client.chat.completions.create(
      model="gpt-4o-mini",
      messages=[{"role": "user", "content": "ping"}],
  )
  print(response.choices[0].message.content)
  ```

  ```python Anthropic SDK theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  import os

  import anthropic

  client = anthropic.Anthropic(
      base_url=os.environ["ANTHROPIC_BASE_URL"],
      api_key=os.environ["LANGSMITH_API_KEY"],
  )
  message = client.messages.create(
      model="claude-sonnet-4-6",
      max_tokens=1024,
      messages=[{"role": "user", "content": "ping"}],
  )
  print(message.content[0].text)
  ```

  ```python LangChain theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  import os

  from langchain.agents import create_agent
  from langchain.chat_models import init_chat_model

  # Anthropic shown here; OpenAI and Gemini are also supported by swapping base_url and model_provider.
  model = init_chat_model(
      model="claude-sonnet-4-6",
      model_provider="anthropic",
      base_url=os.environ["ANTHROPIC_BASE_URL"],
      api_key=os.environ["LANGSMITH_API_KEY"],
  )
  agent = create_agent(model=model, system_prompt="You are a helpful assistant.")
  result = agent.invoke({"messages": [{"role": "user", "content": "ping"}]})
  print(result["messages"][-1].content)
  ```
</CodeGroup>

A `200` response with a chat completion confirms the gateway, your API key, and your role permissions are all working.

## 3. View your trace

Open the [LangSmith UI](https://smith.langchain.com?utm_source=docs\&utm_medium=cta\&utm_campaign=langsmith-signup\&utm_content=langsmith-llm-gateway-quickstart) and navigate to the tracing project named `gateway` or `gateway-<short_api_key>-<api_key_id>` in the workspace associated with your API key. You should see a new trace for the call you just made.

<Note>
  If your application also emits its own LangSmith traces (for example, via [LangChain or LangGraph tracing](/langsmith/observability)), the gateway-side trace and your application trace appear as separate runs. Linking gateway traces to the parent application run is not yet supported.
</Note>

## 4. Set a spend policy (optional)

Go to **Settings → Gateway → LLM Gateway** in LangSmith to create a spend policy. For example, you can set a daily \$10 cap on your API key. When the cap is reached, the gateway returns a `402` response with the message: `"Request blocked by gateway policies: R&D Spend Cap"`.

See [Spend policies](/langsmith/llm-gateway-spend-policies) for the full guide on policy dimensions, time windows, and conflict resolution.

## How the gateway handles requests

Here's what the gateway did when you made a call:

1. **Authenticated** your request using the LangSmith API key.
2. **Resolved** the actual provider API key (for example, `OPENAI_API_KEY`) from your workspace's Provider Secrets.
3. **Evaluated** any active policies (spend limits, PII redaction, secrets redaction).
4. **Proxied** the request to the upstream provider.
5. **Traced** the call to LangSmith, including token counts, cost, and any policy events.

Routing through the gateway requires no application code changes.

## Next steps

* [Set up coding agents](/langsmith/llm-gateway-coding-agents): route Claude Code, Codex, or Gemini CLI through the gateway.
* [Spend policies](/langsmith/llm-gateway-spend-policies): configure cost limits across your organization.
* [PII and secrets redaction](/langsmith/llm-gateway-redaction): prevent sensitive data from reaching providers.

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/langsmith/llm-gateway-quickstart.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
