Skip to content
Sign Up Free
AI application platform setup

Dify BetterToken setup: API key, Base URL, and custom models

Connect Dify to BetterToken with a Base URL, API key, and available model, then verify the connection and fix common errors. Practical guidance.

To connect Dify to BetterToken, prepare an API key, enter the Base URL shown below, and choose a current Model ID from the model plaza.

Key settings

FieldValue
API KeyBetterToken API key
Base URLhttps://bettertoken.ai/v1
ModelA current Model ID from the model plaza

Prerequisites

Additional requirements

  • Dify Cloud or a self-hosted Dify instance with plugins enabled
  • Permission to install model plugins and manage workspace models

Install

Install the OpenAI-compatible model plugin

Open Model Providers

In the Dify workspace, go to Integrations > Model Providers.

Install the official plugin

Click Install model providers, search for OpenAI-API-compatible, and install it.

Dify manages model providers as workspace-level plugins. After installation, apps with the required workspace permissions can select models from this provider.

Add a custom model

On the OpenAI-API-compatible card, click Add Model. If the card first shows Setup or Configure, open it and then choose the option to add a model.

Manual setup

Complete this setup in the Dify model-provider UI. You do not need to edit a configuration file.

FieldValue
API KeyBetterToken API key
Base URLhttps://bettertoken.ai/v1
ModelA current Model ID from the model plaza

Enter the model configuration

Use these values for the first model:

Dify fieldRecommended value
Model TypeLLM
Model Namea model ID from the model plaza
Model display namethe same value as Model Name is fine
API Keyyour BetterToken API key
API Base URLhttps://bettertoken.ai/v1
model name for API endpointthe same model ID as Model Name
Completion modeChat
Model context sizematch the selected model; keep the plugin default if unsure
Upper bound for max tokensdo not exceed the selected model; keep the plugin default for the first test
Compatibility modeOpenAI compatible / strict
Token parameter nameAuto
Function Call TypeNot Support for the first test

Use conservative values for the remaining optional capabilities:

  • Thinking Mode Support: enable it only after confirming model support
  • Stream function calling: select Not Support for the first test
  • Vision Support: enable it only when both the model and endpoint accept image input
  • Structured Output: keep it off until plain chat works

Keep Include Usage in Stream (stream_include_usage) at its default, Enabled. It adds stream_options: {include_usage: true} to request token counts in the final stream chunk; disable it only if the endpoint rejects that field. Stream mode auth (stream_mode_auth) defaults to Not Use; choosing Use makes credential validation use a streaming request, without changing normal generation settings. See the official provider fields.

Click Save. Dify validates the API Key, Base URL, and model ID.

Use the model in an app

Create or open a Dify app

Open a Chatbot, Agent, Chatflow, or Workflow.

Select the model

In the app model selector or an LLM node, choose the model you added under OpenAI-API-compatible.

Test plain chat first

Run the first request with a short text input and no tools or images:

Reply with exactly: Connection successful

Enable Agent capabilities afterward

After plain chat works, edit the model configuration if you need tool calls. Set Function Call Type to the mode supported by the model. OpenAI-compatible tool calling usually uses Tool Call, but you must verify support for the selected model and endpoint.

Verify the connection

Send a short test prompt. If the tool returns a response without an authentication or Model ID error, the connection works. Fully restart the tool after changing its configuration.

Switch models

Open the model selector or change the Model field in the configuration. Use the exact Model ID from the model plaza, then restart the current session.

Dify stores custom configuration per model ID. To add another model, click Add Model again under the same provider. Use the new ID for both Model Name and model name for API endpoint. You can reuse the Base URL and API Key.

Common errors

Saving returns 401

  • Check that the API Key is complete
  • Copy the exact Model ID from the model plaza.
  • Check the key status and balance in the BetterToken Dashboard

Saving returns 404

  • The API Base URL must be https://bettertoken.ai/v1
  • Do not append /chat/completions
  • Make sure model name for API endpoint exactly matches the model plaza ID

Dify reports model not found

Model Name can affect how Dify displays and selects the model. The actual request model is controlled by model name for API endpoint. Use the same model ID in both fields.

Plain chat works, but Agent tools fail

Set Function Call Type back to Not Support and verify a basic LLM node. Change it to Tool Call only when the selected model supports tool calling, then test the tool arguments again.

Knowledge cannot use this model as an Embedding Model

This is expected. A chat LLM cannot replace an embedding model. This guide does not confirm BetterToken embedding or rerank endpoints for Dify; configure a supported embedding provider separately for Knowledge.

Advanced setup

Technical details

Protocol, endpoint, and internal provider fields

This setup uses https://bettertoken.ai/v1. The tool appends the OpenAI-compatible endpoint path. Do not add /chat/completions or /responses unless a specific field explicitly requires it.