Contents
To use SolCard Inference with LangChain in Python, create a ChatOpenAI with base_url="https://api.solcardinference.ai/v1", your sk-si- key and model="solcard-inference-fast". That covers plain chat, chains and tool calls. Everything about LangChain below comes from its own docs; we haven’t run it ourselves. Below are the LangChain defaults worth changing for a non-OpenAI endpoint, and the LangChain features our API rejects.
What you need
- A SolCard Inference API key. Make one on the dashboard’s API keys page. Keys start with
sk-si-and are shown once. - Some balance or a plan. One prepaid USD balance pays for every key and model; see how billing works.
- Python with
langchain-openai, orlangchain-anthropicif you’d rather use the Anthropic route below.
Set up ChatOpenAI
LangChain’s Chat Completions compatibility note says you “can use ChatOpenAI with a custom base_url” for providers that speak Chat Completions. Ours does.
pip install -U langchain-openai
export SOLCARD_INFERENCE_KEY=sk-si-...
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="solcard-inference-fast",
base_url="https://api.solcardinference.ai/v1",
api_key=os.environ["SOLCARD_INFERENCE_KEY"],
max_tokens=4096,
stream_usage=True,
)
print(llm.invoke("Say hello in five words.").content)
Pass base_url in code rather than through an environment variable. LangChain’s credentials section checks an explicit base_url first, then OPENAI_API_BASE, then OPENAI_BASE_URL. A stray OPENAI_BASE_URL left in your shell for another tool won’t win over the argument.
Keep max_tokens at or under 32,768. That’s the most any of our models writes per request, and our Chat Completions reference accepts max_tokens as an alias for max_completion_tokens. LangChain’s docs say it converts max_tokens to max_completion_tokens anyway, so either name lands in the same place.
Turn on stream_usage
Set stream_usage=True yourself. LangChain’s docs say that when OPENAI_BASE_URL is set, it leaves streaming usage off by default “because many non-OpenAI endpoints don’t support streaming token usage.” Ours does: stream_options: { "include_usage": true } “adds a final usage chunk”, per our Chat Completions reference. With it on, a streamed call reports its tokens like any other:
full = None
for chunk in llm.stream("Explain what a race condition is."):
print(chunk.content, end="", flush=True)
full = chunk if full is None else full + chunk
print(full.usage_metadata)
That matters for an agent loop, where you’d otherwise lose track of what each step costs.
Reasoning and the Responses API
Reasoning is off by default, except on solcard-inference-large, which always reasons, per our reasoning guide. Reasoning tokens are billed as output.
ChatOpenAI won’t keep reasoning text from a third-party endpoint. LangChain’s docs say it “targets official OpenAI API specifications only,” and fields like reasoning_content “are not extracted or preserved.” You still get the answer, and you still pay for the reasoning tokens. If you only need the answer, this changes nothing.
To turn reasoning up on Fast or Base, LangChain’s docs describe a reasoning_effort parameter on ChatOpenAI (from langchain-openai 1.4.1) that “translates to reasoning.effort”. They also say setting reasoning routes ChatOpenAI to the Responses API. Our API documents reasoning_effort on Chat Completions and reasoning.effort on Responses, both taking none, low, medium or high.
Leave use_previous_response_id off, and don’t pass previous_response_id. LangChain’s Responses API section offers both so the server can carry the conversation. Our errors page lists previous_response_id and store: true as unsupported_parameter: there’s no stored response on our side to continue from. Send the full message list with each call instead.
Or use ChatAnthropic
ChatAnthropic works too, with the base URL https://api.solcardinference.ai, no /v1. Our quickstart gives that URL for Anthropic SDKs, because they add /v1/messages themselves. LangChain’s reference names the field anthropic_api_url, with base_url as its alias.
import os
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(
model="solcard-inference-large",
base_url="https://api.solcardinference.ai",
api_key=os.environ["SOLCARD_INFERENCE_KEY"],
max_tokens=8192,
)
Watch the environment here. If you don’t pass a base URL, the reference says ChatAnthropic reads ANTHROPIC_API_URL, then ANTHROPIC_BASE_URL. If you also set ANTHROPIC_BASE_URL for Claude Code, the same value works for both.
This route is the one to pick if you want to control thinking. Our Messages endpoint takes thinking.type as enabled, adaptive or disabled, and LangChain’s extended thinking section passes a thinking parameter at init or per call. Our errors page rejects thinking on any endpoint other than Messages, so don’t send it through ChatOpenAI.
Check it works
Rule out LangChain first: if this curl fails, the problem is the key or the URL.
curl https://api.solcardinference.ai/v1/models \
-H "Authorization: Bearer $SOLCARD_INFERENCE_KEY"
The list should name solcard-inference-fast, -large and -base. If it does, run the invoke example above, then the streaming one, and check that usage_metadata isn’t empty.
Picking a model per chain
Make one ChatOpenAI per model and hand each chain step the one it needs. Fast suits routing, extraction and summaries; Large suits the step that has to get it right. Base has a 262,144-token context, so keep your longest retrieved context off it. Fast, Large or Base compares them.
A retrieval chain that sends 6,000 tokens of context and gets 400 back costs about $0.0085 a call on Fast, or $8.50 per 1,000. On Large it’s about $25 per 1,000 before reasoning tokens. An agent makes several calls per task, so multiply by its steps. On a plan, mind the per-minute limit: 120 requests on Starter, 300 on Pro, 600 on Max.
Troubleshooting
These are the API’s codes, from our errors page. How LangChain wraps them in its exceptions isn’t covered here.
- 401
invalid_api_key: the key is missing, revoked or unknown. - 400
model_not_found: the model id doesn’t match. Usesolcard-inference-fast,-largeor-base. - 400
unsupported_parameter: the errors page listsnabove 1,best_of,previous_response_id,store: trueandthinkingoutside Messages. - 400
unsupported_content: an image or file reached the model. Our models take text only. - 402
insufficient_balance: top up, then retry. - 429
rate_limitedorplan_limit_reached: too many requests a minute, or the plan’s 5-hour or weekly limit is used up.
FAQ
Is there a SolCard Inference LangChain package?
No. ChatOpenAI or ChatAnthropic with a base URL is the whole integration.
Which one should I use, ChatOpenAI or ChatAnthropic?
ChatOpenAI if your code already uses it. ChatAnthropic if you want to control thinking with the thinking parameter.
Do tool calls work?
Function tools do, on all three endpoints, per our tool-calling guide. The guide says other tool types, built-in tools included, return 400 unsupported_tool, so the built-in web search that LangChain’s docs show for ChatOpenAI won’t work here.
Are my prompts stored? No. Prompts and responses are never logged or stored. Keeps nothing follows one request through.
What about TypeScript? See the Vercel AI SDK guide.