For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
CoreWeave Serverless Inference
Route agentgateway LLM traffic to open models and custom LoRA adapters served by CoreWeave Serverless Inference.
Configure CoreWeave Serverless Inference as an LLM provider in agentgateway. CoreWeave Serverless Inference serves open models and your custom LoRA adapters through an OpenAI-compatible Chat Completions API.
You can connect to CoreWeave with an AgentgatewayModel or an AgentgatewayBackend. The CoreWeave model preset sends Chat Completions requests to https://api.inference.wandb.ai/v1. Agentgateway converts Messages and Responses requests to Chat Completions before it sends them to CoreWeave. The AgentgatewayBackend approach sends Chat Completions requests only.
For translated Responses requests, include the conversation history in input on each turn. Use /v1/chat/completions for image inputs because Responses conversion drops images.
CoreWeave model names use the Hugging Face <vendor>/<model> format, such as meta-llama/Llama-3.1-8B-Instruct. LoRA adapters use a wandb-artifact:///<team>/<project>/<artifact-name>:<alias-or-version> URI as the model name.
Before you begin
- Install and set up an agentgateway proxy.
- To use the AgentgatewayModel approach, allow the
AgentgatewayModelroute kind on thehttplistener of theagentgateway-proxyGateway. For the steps, see Enable LLM serving on a listener.
Set up provider credentials
Store your CoreWeave API key in a Secret. The model and backend examples both reference this Secret.
Get an API key from your CoreWeave settings.
Save the API key in an environment variable.
export COREWEAVE_API_KEY='<your-api-key>'Create a Kubernetes Secret to store your API key.
kubectl apply -f- <<EOF apiVersion: v1 kind: Secret metadata: name: coreweave-secret namespace: agentgateway-system type: Opaque stringData: Authorization: $COREWEAVE_API_KEY EOF
Chat Completions requests with an AgentgatewayModel
The models attach directly to the Gateway listener, so you do not create an AgentgatewayBackend or an HTTPRoute.
Create the following AgentgatewayModel resources. The
coreweave-llamamodel servesmeta-llama/Llama-3.1-8B-Instruct. Thecoreweave-loramodel serves every LoRA adapter in themy-team/my-projectCoreWeave project.kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayModel metadata: name: coreweave-llama namespace: agentgateway-system spec: parentRefs: - group: gateway.networking.k8s.io kind: Gateway name: agentgateway-proxy sectionName: http match: model: meta-llama/Llama-3.1-8B-Instruct provider: CoreWeave policies: auth: secretRef: name: coreweave-secret --- apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayModel metadata: name: coreweave-lora namespace: agentgateway-system spec: parentRefs: - group: gateway.networking.k8s.io kind: Gateway name: agentgateway-proxy sectionName: http match: model: wandb-artifact:///my-team/my-project/* provider: CoreWeave policies: auth: secretRef: name: coreweave-secret EOFReview the following table to understand this configuration. For more information, see the API docs.
Setting Description spec.match.modelThe model name that clients send in requests. The model forwards the same name to CoreWeave. The wandb-artifact:///my-team/my-project/*pattern matches every LoRA artifact URI in themy-team/my-projectproject.spec.providerThe CoreWeavepreset. The preset supplies the default URL,https://api.inference.wandb.ai/v1, and the Chat Completions request format.spec.policies.auth.secretRefThe Secret that holds your CoreWeave API key. Send a Chat Completions request to the
meta-llama/Llama-3.1-8B-Instructmodel.curl "http://$INGRESS_GW_ADDRESS/v1/chat/completions" \ -H 'Content-Type: application/json' \ -d '{ "model": "meta-llama/Llama-3.1-8B-Instruct", "messages": [{"role": "user", "content": "Explain retrieval-augmented generation in one sentence."}] }' | jq
Attribute usage to a Forge project
By default, CoreWeave attributes usage to the inference project in your default team. To attribute usage to a different project, add the following under spec.policies in the model resource and replace my-team/my-project with your Forge team and project.
headers:
request:
set:
- name: OpenAI-Project
value: my-team/my-projectServe a custom LoRA adapter
CoreWeave Serverless Inference can serve a LoRA adapter on top of a supported base model. You upload the adapter to your CoreWeave team as a lora artifact. Then, you send the artifact URI as the model name. The coreweave-lora model from the previous section forwards the URI to CoreWeave without changes, so you do not need a separate AgentgatewayModel for each adapter.
Train or export a LoRA adapter in PEFT format for a base model that supports LoRA. For the list of base models and the maximum LoRA rank for each, see Bring your own LoRA.
Upload the adapter as a
loraartifact. Setwandb.base_modelto the base model andstorage_regiontocoreweave-us. For a complete example, see the Create a LoRA tutorial.import wandb run = wandb.init(entity="my-team", project="my-project") artifact = wandb.Artifact( "my_lora", type="lora", metadata={"wandb.base_model": "meta-llama/Llama-3.1-8B-Instruct"}, storage_region="coreweave-us", ) artifact.add_dir("<path-to-lora-weights>") run.log_artifact(artifact)Send a Chat Completions request with the artifact URI as the model name.
curl "http://$INGRESS_GW_ADDRESS/v1/chat/completions" \ -H 'Content-Type: application/json' \ -d '{ "model": "wandb-artifact:///my-team/my-project/my_lora:latest", "messages": [{"role": "user", "content": "Say hello."}] }' | jq
The built-in model catalog includes prices for the CoreWeave base models. The catalog does not include LoRA artifact URIs, so agentgateway does not compute a cost for LoRA requests unless you add the URIs to a custom model catalog.
Response settings and prefix caching
For Chat Completions requests, agentgateway forwards the CoreWeave response settings, including JSON mode and structured output (response_format), tool calling (tools and tool_choice), and streaming (stream). For streaming requests, agentgateway sets stream_options.include_usage so that it can record token usage.
CoreWeave caches prompt prefixes automatically on supported models. When a response reuses the cache, CoreWeave reports the cached tokens in usage.prompt_tokens_details.cached_tokens. Agentgateway records these tokens as cache reads and uses the cache read price from the model catalog to compute the cost.
CoreWeave can reuse a cached prefix for any request that has the same prefix and the same cache_salt value. All requests through agentgateway use the same CoreWeave API key. To keep the cache of one caller separate from the cache of other callers, set cache_salt for each caller. Use a final transformation, so that agentgateway sets cache_salt after it converts Messages and Responses requests to Chat Completions. A transformation that runs before the conversion does not keep cache_salt.
The following example adds cache_salt to the coreweave-llama model from the sub claim of the caller’s JWT. The example requires JWT authentication on the Gateway.
kubectl patch AgentgatewayModel coreweave-llama -n agentgateway-system --type merge -p '
spec:
policies:
finalTransformations:
- field: cache_salt
expression: "\"tenant-\" + jwt.sub"
'Chat Completions requests with an AgentgatewayBackend
Use this approach to select the backend with an HTTPRoute.
Create an AgentgatewayBackend that points the
openaiprovider at CoreWeave.kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayBackend metadata: name: coreweave namespace: agentgateway-system spec: ai: provider: openai: model: meta-llama/Llama-3.1-8B-Instruct host: api.inference.wandb.ai port: 443 path: /v1/chat/completions policies: auth: secretRef: name: coreweave-secret tls: sni: api.inference.wandb.ai EOFCreate an HTTPRoute that routes requests on the
/coreweavepath to the AgentgatewayBackend.kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: coreweave namespace: agentgateway-system spec: parentRefs: - name: agentgateway-proxy namespace: agentgateway-system rules: - matches: - path: type: PathPrefix value: /coreweave backendRefs: - name: coreweave namespace: agentgateway-system group: agentgateway.dev kind: AgentgatewayBackend EOFSend a Chat Completions request to the route.
curl "http://$INGRESS_GW_ADDRESS/coreweave" \ -H 'Content-Type: application/json' \ -d '{ "model": "meta-llama/Llama-3.1-8B-Instruct", "messages": [{"role": "user", "content": "Explain retrieval-augmented generation in one sentence."}] }' | jq
Next steps
To connect other providers that expose an OpenAI-compatible API, see OpenAI-compatible providers.
Cleanup
You can remove the resources that you created in this guide.kubectl delete AgentgatewayModel coreweave-llama coreweave-lora -n agentgateway-system
kubectl delete HTTPRoute coreweave -n agentgateway-system
kubectl delete AgentgatewayBackend coreweave -n agentgateway-system
kubectl delete secret coreweave-secret -n agentgateway-system